﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using NetCoreCMS.Common;
using NetCoreCMS.Common.OAuth;
using NetCoreCMS.IServices;
using NetCoreCMS.Models;
using NetCoreCMS.ShopCart;

namespace NetCoreCMS.Web.Controllers
{
    public class Submit_AjaxController : Controller
    {
        #region MyRegion
        public IMail_templateService _mail_template { get; set; }
        public ISms_templateService _sms_template { get; set; }
        public IUser_codeService _user_code { get; set; }
        public IUser_point_logService _user_point_log { get; set; }
        public IUser_amount_logService _user_amount_log { get; set; }
        public IArticle_commentService _article_comment { get; set; }
        public IArticleService _article { get; set; }
        public IUsersService _users { get; set; }
        public IUser_login_logService _user_login_log { get; set; }
        public IPaymentService _payment { get; set; }
        public IUser_rechargeService _user_recharge { get; set; }
        public IUser_messageService _user_message { get; set; }
        public IUser_addr_bookService _user_addr_book { get; set; }
        public IArticle_goodsService _article_goods { get; set; }
        public IUser_group_priceService _user_group_price { get; set; }
        public IUser_groupsService _user_groups { get; set; }
        public IExpressService _express { get; set; }
        public IOrdersService _orders { get; set; }
        public IFeedbackService _feeback { get; set; }
        public ILinkService _link { get; set; }
        public IUser_oauthService _user_oauth { get; set; }
        public ISite_paymentService _site_payment { get; set; }
        public IWebHostEnvironment _env { get; set; }
        public IShopService _shop { get; set; }
        public IShop_ApplyService _shop_apply { get; set; }
        public IApplyService _apply { get; set; }
        public ITransferService _transfer { get; set; }
        public IShop_BillsService _shop_bills { get; set; }
        public IBillsService _bills { get; set; }
        private Userconfig userConfig;
        private Sysconfig sysConfig;
        private Orderconfig orderConfig;
        private AliSMS sendSMS;
        ShopCartHelper shopcart;
        #endregion
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            base.OnActionExecuting(context);
            userConfig = Common.XMLConfig.Userconfig.loadConfig(_env.ContentRootPath);
            sysConfig = Common.XMLConfig.Sysconfig.loadConfig(_env.ContentRootPath);
            orderConfig = Common.XMLConfig.Orderconfig.loadConfig(_env.ContentRootPath);
            sendSMS=new AliSMS(sysConfig.smsusername, sysConfig.smspassword, sysConfig.smssignname);
            shopcart = new ShopCartHelper(_article, _user_groups, _article_goods,context.HttpContext);
            //取得处事类型
            string action = Request.Query["action"];

            switch (action)
            {
                case "comment_add": //提交评论
                    comment_add(context);
                    break;
                case "comment_list": //评论列表
                    comment_list(context);
                    break;
                case "validate_username": //验证用户名
                    validate_username(context);
                    break;
                case "user_login": //用户登录
                    user_login(context);
                    break;
                case "user_check_login": //检查用户是否登录
                    user_check_login(context);
                    break;
                case "user_register": //用户注册
                    user_register(context);
                    break;
                case "user_verify_smscode": //发送手机短信验证码
                    user_verify_smscode(context);
                    break;
                case "user_verify_email": //发送注册验证邮件
                    user_verify_email(context);
                    break;
                case "user_info_edit": //修改用户资料
                    user_info_edit(context);
                    break;
                case "user_avatar_crop": //确认裁剪用户头像
                    user_avatar_crop(context);
                    break;
                case "user_password_edit": //修改密码
                    user_password_edit(context);
                    break;
                case "user_getpassword": //用户取回密码
                    user_getpassword(context);
                    break;
                case "user_repassword": //用户重设密码
                    user_repassword(context);
                    break;
                case "user_invite_code": //申请邀请码
                    user_invite_code(context);
                    break;
                case "user_point_convert": //用户兑换积分
                    user_point_convert(context);
                    break;
                case "user_amount_recharge": //用户在线充值
                    user_amount_recharge(context);
                    break;
                case "user_cash_pay": //用户向商家付款
                    user_cash_pay(context);
                    break;
                case "user_message_add": //发布站内短消息
                    user_message_add(context);
                    break;
                case "user_address_edit": //编辑用户收货地址
                    user_address_edit(context);
                    break;
                case "user_address_default": //设置用户默认收货地址
                    user_address_default(context);
                    break;
                case "user_point_delete": //删除用户积分明细
                    user_point_delete(context);
                    break;
                case "user_amount_delete": //删除用户收支明细
                    user_amount_delete(context);
                    break;
                case "user_recharge_delete": //删除用户充值记录
                    user_recharge_delete(context);
                    break;
                case "user_message_delete": //删除短信息
                    user_message_delete(context);
                    break;
                case "user_address_delete": //删除用户收货地址
                    user_address_delete(context);
                    break;
                case "get_article_goods_info": //商品信息
                    get_article_goods_info(context);
                    break;
                case "cart_goods_add": //加入结帐商品
                    cart_goods_add(context);
                    break;
                case "cart_goods_buy": //购物车结账商品
                    cart_goods_buy(context);
                    break;
                case "cart_goods_update": //购物车修改商品
                    cart_goods_update(context);
                    break;
                case "cart_goods_delete": //购物车删除商品
                    cart_goods_delete(context);
                    break;
                case "order_save": //保存购物订单
                    order_save(context);
                    break;
                case "order_cancel": //用户取消订单
                    order_cancel(context);
                    break;
                case "edit_order_address": //修改收货地
                    edit_order_address(context);
                    break;
            }
        }
        public async Task<IActionResult> Index()
        {
            //取得处事类型
            string action = Request.Query["action"];
            ContentResult result= Content("SubmitAPI");
            switch (action)
            {
                case "view_cart_count": //输出当前购物车总数
                    result = view_cart_count();
                    break;
                case "feedback_add": //添加留言
                    result = feedback_add();
                    break;
                case "link_add": //添加链接
                    result = link_add();
                    break;
                case "user_oauth_bind": //绑定第三方登录账户
                    result=user_oauth_bind();
                    break;
                case "user_oauth_register": //注册第三方登录账户
                    result=user_oauth_register();
                    break;
                //验证直推人是否可用OK
                case "direct_validate":
                    result = direct_validate();
                    break;
                //验证接点人是否可用OK
                case "indirect_validate":
                    result = indirect_validate();
                    break;
                //升级用户级别
                case "upgrade":
                    result = upgrade();
                    break;
                //商户资金提现
                case "shoppoint_tixian":
                    result = shoppoint_tixian();
                    break;
                //激活报单人员
                case "baodan_pass":
                    result = baodan_pass();
                    break;
                //用户自身激活审核
                case "user_pass":
                    result = user_pass();
                    break;
                //用户资金提现
                case "user_point_tixian":
                    result = user_point_tixian(); 
                    break;
                //向其它会员转币或者向商户支付
                case "user_point_transfer":
                    result = user_point_transfer();
                    break;
                //积分转成购物
                case "user_point_conversion":
                    result = user_point_conversion();
                    break;
                case "user_pay":
                    result = user_pay();
                    break;
                //验证转让名是否可用
                case "validate_touser":
                    result = validate_touser();
                    break;
            }
            return result;
        }
        #region 会员用户方法==========================================
        /// <summary>
        /// 判断用户是否已经登录(解决Session超时问题)
        /// </summary>
        public bool IsUserLogin()
        {
            //如果Session为Null
            if (Request.HttpContext.Session.Get(CMSKeys.SESSION_USER_INFO) != null)
            {
                return true;
            }
            else
            {
                //检查Cookies
                string username = HttpContext.Request.Cookies[CMSKeys.COOKIE_USER_NAME_REMEMBER];
                string password = HttpContext.Request.Cookies[CMSKeys.COOKIE_USER_PWD_REMEMBER];
                if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password))
                {
                    Users model = _users.GetModel(username, password, 0, 0, false);
                    if (model != null)
                    {
                        HttpContext.Session.Set(CMSKeys.SESSION_USER_INFO, ByteConvertHelper.Object2Bytes(model));
                        return true;
                    }
                }
            }
            return false;
        }

        /// <summary>
        /// 取得用户信息
        /// </summary>
        public Users GetUserInfo()
        {
            if (IsUserLogin())
            {
                Users model = ByteConvertHelper.Bytes2Object<Users>(Request.HttpContext.Session.Get(CMSKeys.SESSION_USER_INFO));
                if (model != null)
                {
                    //为了能查询到最新的用户信息，必须查询最新的用户资料
                    model = _users.GetModel(model.id);
                    return model;
                }
            }
            return null;
        }
        #endregion

        #region 提交评论的处理方法OK===========================
        private void comment_add(ActionExecutingContext context)
        {
            StringBuilder strTxt = new StringBuilder();
            Article_comment model = new Article_comment();

            string code = Request.Form["txtCode"];
            int article_id = 0;
            int.TryParse(Request.Query["article_id"],out article_id);
            string _content = Request.Form["txtContent"];
            //校检验证码
            string result = verify_code(context, code);
            if (result != "success")
            {
                context.Result=Content(result);
                return;
            }
            if (article_id == 0)
            {
                context.Result = Content("{\"status\": 0, \"msg\": \"对不起，信息参数传输有误！\"}");
                return;
            }
            if (string.IsNullOrEmpty(_content))
            {
                context.Result = Content("{\"status\": 0, \"msg\": \"对不起，请输入评论的内容！\"}");
                return;
            }
            //检查该文章是否存在
            Article artModel = _article.GetModel(article_id);
            if (artModel == null)
            {
                context.Result = Content("{\"status\": 0, \"msg\": \"对不起，主题不存在或已删除！\"}");
                return;
            }
            //检查用户是否登录
            int user_id = 0;
            string user_name = "匿名用户";
            Users userModel = GetUserInfo();
            if (userModel != null)
            {
                user_id = userModel.id;
                user_name = userModel.user_name;
            }
            model.channel_id = artModel.channel_id;
            model.article_id = artModel.id;
            model.content = _content;
            model.user_id = user_id;
            model.user_name = user_name;
            model.user_ip = CMSRequest.GetClientUserIp(context.HttpContext);
            model.is_lock = sysConfig.commentstatus; //审核开关
            model.add_time = DateTime.Now;
            model.is_reply = 0;
            if (_article_comment.Add(model) > 0)
            {
                context.Result=Content("{\"status\": 1, \"msg\": \"恭喜您，评论提交成功！\"}");
                return;
            }
            context.Result = Content("{\"status\": 0, \"msg\": \"对不起，保存过程中发生错误！\"}");
            return;
        }
        #endregion

        #region 取得评论列表方法OK=============================
        private void comment_list(ActionExecutingContext context)
        {
            int article_id = 0;
            int.TryParse(Request.Query["article_id"],out article_id);
            int page_index = 0;
            int.TryParse(Request.Query["page_index"],out page_index);
            int page_size = 0;
            int.TryParse(Request.Query["page_size"],out page_size);
            int totalcount;
            StringBuilder strTxt = new StringBuilder();

            if (article_id == 0 || page_size == 0)
            {
                context.Result=Content("获取失败，传输参数有误！");
                return;
            }

            var ds = _article_comment.GetList(page_index, page_size, string.Format("where is_lock=0 and article_id={0}",
                article_id.ToString()), "add_time asc");
            totalcount=_article_comment.RecordCount(string.Format("where is_lock=0 and article_id={0}",
                article_id.ToString()));
            //如果记录存在
            if (ds.Count > 0)
            {
                strTxt.Append("[");
                for (int i = 0; i < ds.Count; i++)
                {
                    var dr = ds[i];
                    strTxt.Append("{");
                    strTxt.Append("\"user_id\":" + dr.user_id);
                    strTxt.Append(",\"user_name\":\"" + dr.user_name + "\"");
                    if (dr.user_id > 0)
                    {
                        Users userModel = _users.GetModel(dr.user_id);
                        if (userModel != null)
                        {
                            strTxt.Append(",\"avatar\":\"" + userModel.avatar + "\"");
                        }
                    }
                    strTxt.Append("");
                    strTxt.Append(",\"content\":\"" + dr.content + "\"");
                    strTxt.Append(",\"add_time\":\"" + dr.add_time + "\"");
                    strTxt.Append(",\"is_reply\":" + dr.is_reply);
                    if (dr.is_reply == 1)
                    {
                        strTxt.Append(",\"reply_content\":\"" + dr.reply_content + "\"");
                        strTxt.Append(",\"reply_time\":\"" + dr.reply_time + "\"");
                    }
                    strTxt.Append("}");
                    //是否加逗号
                    if (i < ds.Count - 1)
                    {
                        strTxt.Append(",");
                    }

                }
                strTxt.Append("]");
            }
            context.Result=Content(strTxt.ToString());
            return;
        }
        #endregion

        #region 验证用户名是否可用OK===========================
        private void validate_username(ActionExecutingContext context)
        {
            string username = Request.Query["param"];
            //如果为Null，退出
            if (string.IsNullOrEmpty(username))
            {
                context.Result=Content("{ \"info\":\"用户名不可为空\", \"status\":\"n\" }");
                return;
            }
            //过滤注册用户名字符
            string[] strArray = userConfig.regkeywords.Split(',');
            foreach (string s in strArray)
            {
                if (s.ToLower() == username.ToLower())
                {
                    context.Result = Content("{ \"info\":\"该用户名不可用\", \"status\":\"n\" }");
                    return;
                }
            }
            //查询数据库
            if (!_users.Exists(username.Trim()))
            {
                context.Result = Content("{ \"info\":\"该用户名可用\", \"status\":\"y\" }");
                return;
            }
            context.Result = Content("{ \"info\":\"该用户名已被注册\", \"status\":\"n\" }");
            return;
        }
        #endregion

        #region 用户登录OK=====================================
        private void user_login(ActionExecutingContext context)
        {
            string username = Request.Form["txtUserName"];
            string password = Request.Form["txtPassword"];
            string remember = Request.Form["chkRemember"];
            //检查用户名密码
            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
            {
                context.Result = Content("{\"status\": 0, \"msg\": \"温馨提示：请输入用户名或密码！\"}");
                return;
            }

            Users model = _users.GetModel(username, password, userConfig.emaillogin, userConfig.mobilelogin, true);
            if (model == null)
            {
                context.Result = Content("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误，请重试！\"}");
                return;
            }
            //检查用户是否通过验证
            if (model.status == 1) //待验证
            {
                if (userConfig.regverify == 1)
                {
                    context.Result = Content("{\"status\":1, \"url\":\""
                        + "register?action=sendmail&username=" + model.user_name + "\", \"msg\":\"会员尚未通过验证！\"}");
                }
                else
                {
                    context.Result = Content("{\"status\":1, \"url\":\"" +
                        "register?action=sendsms&username=" + model.user_name + "\", \"msg\":\"会员尚未通过验证！\"}");
                }
                return;
            }
            else if (model.status == 2) //待审核
            {
                context.Result = Content("{\"status\":1, \"url\":\""
                    + "register?action=verify&username=" + model.user_name + "\", \"msg\":\"会员尚未通过审核！\"}");
                return;
            }
            //检查用户每天登录是否获得积分
            if (!_user_login_log.ExistsDay(model.user_name) && userConfig.pointloginnum > 0)
            {
                _user_point_log.Add(model.id, model.user_name, userConfig.pointloginnum, "每天登录获得积分", true); //增加用户登录积分
                model = _users.GetModel(username, password, userConfig.emaillogin, userConfig.mobilelogin, true); //更新一下用户信息
            }
            context.HttpContext.Session.Set(CMSKeys.SESSION_USER_INFO, ByteConvertHelper.Object2Bytes(model));
            //记住登录状态下次自动登录
            if (string.IsNullOrEmpty(remember))
                remember = "false";
            if (remember.ToLower() == "true")
            {
                context.HttpContext.Response.Cookies.Append(CMSKeys.COOKIE_USER_NAME_REMEMBER, model.user_name);
                context.HttpContext.Response.Cookies.Append(CMSKeys.COOKIE_USER_PWD_REMEMBER, model.password);
            }
            else
            {
                //防止Session提前过期
                context.HttpContext.Response.Cookies.Append(CMSKeys.COOKIE_USER_NAME_REMEMBER, model.user_name);
                context.HttpContext.Response.Cookies.Append(CMSKeys.COOKIE_USER_PWD_REMEMBER, model.password);
            }

            //写入登录日志
            _user_login_log.Add(model.id, model.user_name, "会员登录",CMSRequest.GetClientUserIp(HttpContext));
            //返回URL
            context.Result=Content("{\"status\":1, \"msg\":\"会员登录成功！\"}");
            return;
        }
        #endregion

        #region 检查用户是否登录OK=============================
        private void user_check_login(ActionExecutingContext context)
        {
            //检查用户是否登录
            Users model = GetUserInfo();
            if (model == null)
            {
                context.Result=Content("{\"status\":0, \"username\":\"匿名用户\"}");
                return;
            }
            context.Result = Content("{\"status\":1, \"username\":\"" + model.user_name + "\"}");
        }
        #endregion

        #region 用户注册OK=====================================
        private void user_register(ActionExecutingContext context)
        {
            string code = CMSRequest.GetFormString("txtCode",HttpContext);
            string username = CMSRequest.GetFormString("txtUserName", HttpContext);
            string password = CMSRequest.GetFormString("txtPassword", HttpContext);
            string email = CMSRequest.GetFormString("txtEmail", HttpContext);
            string mobile = CMSRequest.GetFormString("txtMobile", HttpContext);
            string userip = CMSRequest.GetClientUserIp(context.HttpContext);

            string direct = CMSRequest.GetFormString("txtDirect", HttpContext);

            var duser=_users.GetModel(direct);
            if(duser==null)
            {
                context.Result = Content("{\"status\":0, \"msg\":\"对不起，推荐人不存在！\"}");
                return;
            }
            if(userConfig.passshare==1&&duser.is_pass==0)
            {
                context.Result = Content("{\"status\":0, \"msg\":\"对不起，推荐人未激活！\"}");
                return;
            }
            if(duser.is_share==0||duser.is_lock==1)
            {
                context.Result = Content("{\"status\":0, \"msg\":\"对不起，推荐人受限制！\"}");
                return;
            }

            #region 验证各种参数信息
            //检查是否开启会员功能
            if (sysConfig.memberstatus == 0)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，会员功能已关闭，无法注册！\"}");
                return;
            }
            if (userConfig.regstatus == 0)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，系统暂不允许注册新用户！\"}");
                return;
            }
            //检查用户输入信息是否为空
            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，用户名和密码不能为空！\"}");
                return;
            }
            //如果开启手机注册则要验证手机
            if (userConfig.regstatus == 2 && string.IsNullOrEmpty(mobile))
            {
                context.Result=Content("{\"status\":0, \"msg\":\"错误：手机号码不能为空！\"}");
                return;
            }
            //如果开启邮箱注册则要验证邮箱
            if (userConfig.regstatus == 3 && string.IsNullOrEmpty(email))
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，电子邮箱不能为空！\"}");
                return;
            }
            //检查用户名
            if (_users.Exists(username))
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，该用户名已经存在！\"}");
                return;
            }
            //如果开启手机登录要验证手机
            if (userConfig.mobilelogin == 1 && !string.IsNullOrEmpty(mobile))
            {
                if (_users.ExistsMobile(mobile))
                {
                    context.Result=Content("{\"status\":0, \"msg\":\"对不起，该手机号码已被使用！\"}");
                    return;
                }
            }
            //如果开启邮箱登录要验证邮箱
            if (userConfig.emaillogin == 1 && !string.IsNullOrEmpty(email))
            {
                if (_users.ExistsEmail(email))
                {
                    context.Result=Content("{\"status\":0, \"msg\":\"对不起，该电子邮箱已被使用！\"}");
                    return;
                }
            }
            //检查同一IP注册时隔
            if (userConfig.regctrl > 0)
            {
                if (_users.Exists(userip, userConfig.regctrl))
                {
                    context.Result=Content("{\"status\":0, \"msg\":\"对不起，同IP在" + userConfig.regctrl + "小时内禁止重复注册！\"}");
                    return;
                }
            }
            //检查默认组别是否存在
            User_groups modelGroup = _user_groups.GetDefault();
            if (modelGroup == null)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"用户尚未分组，请联系网站管理员！\"}");
                return;
            }
            //检查验证码是否正确
            switch (userConfig.regstatus)
            {
                case 1: //验证网页验证码
                    string result1 = verify_code(context, code);
                    if (result1 != "success")
                    {
                        context.Result=Content(result1);
                        return;
                    }
                    break;
                case 2: //验证手机验证码
                    string result2 = verify_sms_code(context, code);
                    if (result2 != "success")
                    {
                        context.Result=Content(result2);
                        return;
                    }
                    break;
                case 4: //验证邀请码
                    string result4 = verify_invite_reg(username, code);
                    if (result4 != "success")
                    {
                        context.Result=Content(result4);
                        return;
                    }
                    break;
            }
            #endregion

            #region 保存用户注册信息
            Users model = new Users();
            model.pid = duser.id;
            model.iid = duser.id;
            model.layer = duser.layer + 1;
            model.group_id = modelGroup.id;
            model.user_name = username;
            model.salt = Utils.GetCheckCode(6); //获得6位的salt加密字符串
            model.password = AESEncryptHelper.Encode(password, model.salt);
            model.email = email;
            model.mobile = mobile;
            model.reg_ip = userip;
            model.reg_time = DateTime.Now;
            //设置用户状态
            if (userConfig.regstatus == 3)
            {
                model.status = 1; //待验证
            }
            else if (userConfig.regverify == 1)
            {
                model.status = 2; //待审核
            }
            else
            {
                model.status = 0; //正常
            }
            //开始写入数据库
            model.id = _users.Add(model);
            if (model.id < 1)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"系统故障，请联系网站管理员！\"}");
                return;
            }
            //检查用户组是否需要赠送积分
            if (modelGroup.point > 0)
            {
                _user_point_log.Add(model.id, model.user_name, modelGroup.point, "注册赠送积分", false);
            }
            //检查用户组是否需要赠送金额
            if (modelGroup.amount > 0)
            {
                _user_amount_log.Add(model.id, model.user_name, modelGroup.amount, "注册赠送金额");
            }
            #endregion

            #region 是否发送欢迎消息
            if (userConfig.regmsgstatus == 1) //站内短消息
            {
                _user_message.Add(1, string.Empty, model.user_name, "欢迎您成为本站会员", userConfig.regmsgtxt);
            }
            else if (userConfig.regmsgstatus == 2 && !string.IsNullOrEmpty(email)) //发送邮件
            {
                //取得邮件模板内容
                Mail_template mailModel = _mail_template.GetModel("welcomemsg");
                if (mailModel != null)
                {
                    //替换标签
                    string mailTitle = mailModel.maill_title;
                    mailTitle = mailTitle.Replace("{username}", model.user_name);
                    string mailContent = mailModel.content;
                    mailContent = mailContent.Replace("{webname}", sysConfig.webname);
                    mailContent = mailContent.Replace("{weburl}", sysConfig.weburl);
                    mailContent = mailContent.Replace("{webtel}", sysConfig.webtel);
                    mailContent = mailContent.Replace("{username}", model.user_name);
                    //发送邮件
                    CMSMail.sendMail(sysConfig.emailsmtp, sysConfig.emailssl,
                        sysConfig.emailusername,
                        AESEncryptHelper.Decode(sysConfig.emailpassword, sysConfig.sysencryptstring),
                        sysConfig.emailnickname,
                        sysConfig.emailfrom,
                        model.email,
                        mailTitle, mailContent);
                }
            }
            else if (userConfig.regmsgstatus == 3 && !string.IsNullOrEmpty(mobile)) //发送短信
            {
                Sms_template smsModel = _sms_template.GetModel("welcomemsg"); //取得短信内容
                if (smsModel != null)
                {
                    //替换标签
                    string msgContent = smsModel.content;
                    msgContent = msgContent.Replace("{webname}", sysConfig.webname);
                    msgContent = msgContent.Replace("{weburl}", sysConfig.weburl);
                    msgContent = msgContent.Replace("{webtel}", sysConfig.webtel);
                    msgContent = msgContent.Replace("{username}", model.user_name);
                    //发送短信
                    string tipMsg = string.Empty;
                    //TODO_sms_message.Send(model.mobile, msgContent, 2, out tipMsg);
                }
            }
            #endregion

            //需要Email验证
            if (userConfig.regstatus == 3)
            {
                string result2 = send_verify_email(model); //发送验证邮件
                if (result2 != "success")
                {
                    context.Result=Content(result2);
                    return;
                }
                context.Result = Content("{\"status\":1, \"msg\":\"注册成功，请进入邮箱验证激活账户！\", \"url\":\""
                    + "register?action=sendmail&username=" + model.user_name + "\"}");
            }
            //需要人工审核
            else if (userConfig.regverify == 1)
            {
                context.Result = Content("{\"status\":1, \"msg\":\"注册成功，请等待审核通过！\", \"url\":\""
                    + "register?action=verify&username=" + model.user_name + "\"}");
            }
            else
            {
                context.HttpContext.Session.Set(CMSKeys.SESSION_USER_INFO, ByteConvertHelper.Object2Bytes(model));
                //防止Session提前过期
                context.HttpContext.Response.Cookies.Append(CMSKeys.COOKIE_USER_NAME_REMEMBER, model.user_name);
                context.HttpContext.Response.Cookies.Append(CMSKeys.COOKIE_USER_PWD_REMEMBER, model.password);
                //写入登录日志
                _user_login_log.Add(model.id, model.user_name, "会员登录",CMSRequest.GetClientUserIp(HttpContext));
                context.Result=Content("{\"status\":1, \"msg\":\"注册成功，欢迎成为本站会员！\", \"url\":\""
                    + "usercenter/index" + "\"}");
            }
            return;
        }
        #endregion

        #region 发送手机短信验证码OK===========================
        private void user_verify_smscode(ActionExecutingContext context)
        {
            string mobile = CMSRequest.GetFormString("mobile",HttpContext);
            //检查手机
            if (string.IsNullOrEmpty(mobile))
            {
                context.Result=Content("{\"status\":0, \"msg\":\"发送失败，请填写手机号码！\"}");
            }
            string result = send_verify_sms_code(context, mobile);
            if (result != "success")
            {
                context.Result = Content(result);
                return;
            }
            context.Result = Content("{\"status\":1, \"time\":\"" + userConfig.regsmsexpired + "\", \"msg\":\"手机验证码发送成功！\"}");
            return;
        }
        #endregion

        #region 发送注册验证邮件OK=============================
        private void user_verify_email(ActionExecutingContext context)
        {
            string username = Request.Form["username"];

            if (string.IsNullOrEmpty(username))
            {
                context.Result=Content("{\"status\":0, \"msg\":\"请检查用户名是否正确！\"}");
                return;
            }
            //检查邮件是否过快
            string cookie = context.HttpContext.Request.Cookies[CMSKeys.COOKIE_USER_EMAIL];
            if (cookie == username)
            {
                context.Result = Content("{\"status\":0, \"msg\":\"邮件发送间隔为二十分钟，请稍候再提交吧！\"}");
                return;
            }
            Users model = _users.GetModel(username);
            if (model == null)
            {
                context.Result = Content("{\"status\":0, \"msg\":\"该用户不存在或已删除！\"}");
                return;
            }
            if (model.status != 1)
            {
                context.Result = Content("{\"status\":0, \"msg\":\"该用户不需要邮箱验证！\"}");
                return;
            }
            string result = send_verify_email(model);
            if (result != "success")
            {
                context.Result = Content(result);
                return;
            }
            context.Result = Content("{\"status\":1, \"msg\":\"邮件已发送，请进入邮箱查看！\"}");
            context.HttpContext.Response.Cookies.Append(CMSKeys.COOKIE_USER_EMAIL, username); //20分钟内无重复发送
            return;
        }
        #endregion

        #region 修改用户信息OK=================================
        private void user_info_edit(ActionExecutingContext context)
        {
            //检查用户是否登录
            Users model = GetUserInfo();
            if (model == null)
            {
                context
                    .Result = Content("{\"status\":0, \"msg\":\"对不起，用户尚未登录或已超时！\"}");
                return;
            }
            string nick_name = Request.Form["txtNickName"];
            string sex = Request.Form["rblSex"];
            string birthday = Request.Form["txtBirthday"];
            string email = Request.Form["txtEmail"];
            string mobile = Request.Form["txtMobile"];
            string telphone = Request.Form["txtTelphone"];
            string qq = Request.Form["txtQQ"];
            string bankname = Request.Form["txtBankName"];
            string banknumber = Request.Form["txtBankNumber"];
            string msn = Request.Form["txtMsn"];
            string province = Request.Form["txtProvince"];
            string city = Request.Form["txtCity"];
            string area = Request.Form["txtArea"];
            string address = Request.Form["txtAddress"];
            //检查昵称
            if (string.IsNullOrEmpty(nick_name))
            {
                context.Result = Content("{\"status\":0, \"msg\":\"对不起，请输入您的姓名昵称！\"}");
                return;
            }
            //检查省市区
            if (string.IsNullOrEmpty(province) || string.IsNullOrEmpty(city) || string.IsNullOrEmpty(area))
            {
                context.Result = Content("{\"status\":0, \"msg\":\"对不起，请选择您所在的省市区！\"}");
                return;
            }
            //检查手机，如开启手机注册或使用手机登录需要检查
            if (userConfig.regstatus == 2 || userConfig.mobilelogin == 1)
            {
                if (string.IsNullOrEmpty(mobile))
                {
                    context.Result = Content("{\"status\":0, \"msg\":\"对不起，请输入您的手机号码！\"}");
                    return;
                }
                if (model.mobile != mobile && _users.ExistsMobile(mobile))
                {
                    context.Result = Content("{\"status\":0, \"msg\":\"对不起，该手机号码已被使用！\"}");
                    return;
                }
            }
            //检查邮箱，如开启邮箱注册或使用邮箱登录需要检查
            if (userConfig.regstatus == 3 || userConfig.emaillogin == 1)
            {
                if (string.IsNullOrEmpty(email))
                {
                    context.Result = Content("{\"status\":0, \"msg\":\"对不起，请输入您的电子邮箱！\"}");
                    return;
                }
                if (model.email != email && _users.ExistsEmail(email))
                {
                    context.Result = Content("{\"status\":0, \"msg\":\"对不起，该电子邮箱已被使用！\"}");
                    return;
                }
            }

            //开始写入数据库
            model.nick_name = nick_name;
            model.sex = sex;
            DateTime _birthday;
            if (DateTime.TryParse(birthday, out _birthday))
            {
                model.birthday = _birthday;
            }
            model.email = email;
            model.mobile = mobile;
            model.telphone = telphone;
            model.qq = qq;
            model.bank_name = bankname;
            model.bank_number = banknumber;
            model.msn = msn;
            model.area = province + "," + city + "," + area;
            model.address = address;

            _users.Update(model);
            context.Result = Content("{\"status\":1, \"msg\":\"账户资料已修改成功！\"}");
            return;
        }
        #endregion

        #region 确认裁剪用户头像OK=============================
        private void user_avatar_crop(ActionExecutingContext context)
        {
            //检查用户是否登录
            Users model = GetUserInfo();
            if (model == null)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，用户尚未登录或已超时！\"}");
                return;
            }
            string fileName = Request.Form["hideFileName"];
            int x1 = 0;
            int.TryParse(Request.Query["hideX1"],out x1);
            int y1 = 0;
            int.TryParse(Request.Query["hideY1"],out y1);
            int w = 0;
            int.TryParse(Request.Query["hideWidth"],out w);
            int h = 0;
            int.TryParse(Request.Query["hideHeight"],out h);
            //检查是否图片

            //检查参数
            if (!FileHelper.FileExists(fileName,_env.ContentRootPath) || w == 0 || h == 0)
            {
                context.Result = Content("{\"status\":0, \"msg\":\"对不起，请先上传一张图片！\"}");
                return;
            }
            //取得保存的新文件名
            UpLoad upFiles = new UpLoad(_env.WebRootPath,sysConfig);
            string result = upFiles.CropSaveAs(fileName, 180, 180, w, h, x1, y1);
            Dictionary<string, object> dic = JsonHelper.DataRowFromJSON(result);
            if (dic["status"].ToString() == "0")
            {
                context.Result = Content("{\"status\": 0, \"msg\": \"图片裁剪过程中发生意外错误！\"}");
                return;
            }
            //删除原用户头像
            upFiles.DeleteFile(model.avatar);
            model.avatar = dic["path"].ToString();
            //修改用户头像
            _users.UpdateField(model.id, "avatar='" + model.avatar + "'");
            context.Result = Content("{\"status\": 1, \"msg\": \"头像上传成功！\", \"avatar\": \"" + model.avatar + "\"}");
            return;
        }
        #endregion

        #region 修改登录密码OK=================================
        private void user_password_edit(ActionExecutingContext context)
        {
            //检查用户是否登录
            Users model = GetUserInfo();
            if (model == null)
            {
                context.Result = Content("{\"status\":0, \"msg\":\"对不起，用户尚未登录或已超时！\"}");
                return;
            }
            int user_id = model.id;
            string oldpassword = Request.Form["txtOldPassword"];
            string password = Request.Form["txtPassword"];
            //检查输入的旧密码
            if (string.IsNullOrEmpty(oldpassword))
            {
                context.Result = Content("{\"status\":0, \"msg\":\"请输入您的旧登录密码！\"}");
                return;
            }
            //检查输入的新密码
            if (string.IsNullOrEmpty(password))
            {
                context.Result = Content("{\"status\":0, \"msg\":\"请输入您的新登录密码！\"}");
                return;
            }
            //旧密码是否正确
            if (model.password != AESEncryptHelper.Encode(oldpassword, model.salt))
            {
                context.Result = Content("{\"status\":0, \"msg\":\"对不起，您输入的旧密码不正确！\"}");
                return;
            }
            //执行修改操作
            model.password = AESEncryptHelper.Encode(password, model.salt);
            _users.Update(model);
            context.Result = Content("{\"status\":1, \"msg\":\"您的密码已修改成功，请记住新密码！\"}");
            return;
        }
        #endregion

        #region 用户取回密码OK=================================
        private void user_getpassword(ActionExecutingContext context)
        {
            string code = CMSRequest.GetFormString("txtCode",context.HttpContext);
            string type = CMSRequest.GetFormString("txtType", context.HttpContext);
            string username = CMSRequest.GetFormString("txtUserName", context.HttpContext).Trim();
            //检查用户名
            if (string.IsNullOrEmpty(username))
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，用户名不可为空！\"}");
                return;
            }
            //检查取回密码类型
            if (string.IsNullOrEmpty(type))
            {
                context.Result = Content("{\"status\":0, \"msg\":\"对不起，请选择取回密码类型！\"}");
                return;
            }
            //校检验证码
            string result = verify_code(context, code);
            if (result != "success")
            {
                context.Result = Content(result);
                return;
            }
            //检查用户信息
            Users model = _users.GetModel(username);
            if (model == null)
            {
                context.Result = Content("{\"status\":0, \"msg\":\"对不起，您输入的用户名不存在！\"}");
                return;
            }
            //发送取回密码的短信或邮件
            if (type.ToLower() == "mobile") //使用手机取回密码
            {
                #region 发送短信==================
                if (string.IsNullOrEmpty(model.mobile))
                {
                    context.Result = Content("{\"status\":0, \"msg\":\"您尚未绑定手机号码，无法取回密码！\"}");
                    return;
                }
                Sms_template smsModel = _sms_template.GetModel("usercode"); //取得短信内容
                if (smsModel == null)
                {
                    context.Result = Content("{\"status\":0, \"msg\":\"发送失败，短信模板不存在，请联系管理员！\"}");
                }
                string strcode = Utils.Number(4); //随机验证码
                                                  //检查是否重复提交
                User_code codeModel;
                codeModel = _user_code.GetModel(username, CMSEnums.CodeEnum.RegVerify.ToString(), "d");
                if (codeModel == null)
                {
                    codeModel = new User_code();
                    //写入数据库
                    codeModel.user_id = model.id;
                    codeModel.user_name = model.user_name;
                    codeModel.type = CMSEnums.CodeEnum.Password.ToString();
                    codeModel.str_code = strcode;
                    codeModel.eff_time = DateTime.Now.AddMinutes(userConfig.regsmsexpired);
                    codeModel.add_time = DateTime.Now;
                    _user_code.Add(codeModel);
                }
                //替换标签
                string msgContent = smsModel.content;
                msgContent = msgContent.Replace("{webname}", sysConfig.webname);
                msgContent = msgContent.Replace("{weburl}", sysConfig.weburl);
                msgContent = msgContent.Replace("{webtel}", sysConfig.webtel);
                msgContent = msgContent.Replace("{code}", codeModel.str_code);
                msgContent = msgContent.Replace("{valid}", userConfig.regsmsexpired.ToString());
                //发送短信
                string tipMsg = string.Empty;
                
                bool result1 = sendSMS.Send(model.mobile,smsModel.code,msgContent);
                if (!result1)
                {
                    context.Result = Content("{\"status\":0, \"msg\":\"发送失败，" + tipMsg + "\"}");
                    return;
                }
                context.Result=Content("{\"status\":1, \"msg\":\"手机验证码发送成功！\", \"url\":\""
                    + "?action=mobile&username=" + model.user_name + "\"}");
                return;
                #endregion
            }
            else if (type.ToLower() == "email") //使用邮箱取回密码
            {
                #region 发送邮件==================
                if (string.IsNullOrEmpty(model.email))
                {
                    context.Result = Content("{\"status\":0, \"msg\":\"您尚未绑定邮箱，无法取回密码！\"}");
                    return;
                }
                //生成随机码
                string strcode = Utils.GetCheckCode(20);
                //获得邮件内容
                Mail_template mailModel = _mail_template.GetModel("getpassword");
                if (mailModel == null)
                {
                    context.Result = Content("{\"status\":0, \"msg\":\"邮件发送失败，邮件模板内容不存在！\"}");
                    return;
                }
                //检查是否重复提交
                User_code codeModel;
                codeModel = _user_code.GetModel(username, CMSEnums.CodeEnum.RegVerify.ToString(), "d");
                if (codeModel == null)
                {
                    codeModel = new User_code();
                    //写入数据库
                    codeModel.user_id = model.id;
                    codeModel.user_name = model.user_name;
                    codeModel.type = CMSEnums.CodeEnum.Password.ToString();
                    codeModel.str_code = strcode;
                    codeModel.eff_time = DateTime.Now.AddDays(userConfig.regemailexpired);
                    codeModel.add_time = DateTime.Now;
                    _user_code.Add(codeModel);
                }
                //替换模板内容
                string titletxt = mailModel.maill_title;
                string bodytxt = mailModel.content;
                titletxt = titletxt.Replace("{webname}", sysConfig.webname);
                titletxt = titletxt.Replace("{username}", model.user_name);
                bodytxt = bodytxt.Replace("{webname}", sysConfig.webname);
                bodytxt = bodytxt.Replace("{weburl}", sysConfig.weburl);
                bodytxt = bodytxt.Replace("{webtel}", sysConfig.webtel);
                bodytxt = bodytxt.Replace("{valid}", userConfig.regemailexpired.ToString());
                bodytxt = bodytxt.Replace("{username}", model.user_name);
                bodytxt = bodytxt.Replace("{linkurl}", "https://" + HttpContext.Request.Host.Host.ToLower()
                    + "/web/repassword/index?action=email&code=" + codeModel.str_code);
                //发送邮件
                try
                {
                    CMSMail.sendMail(sysConfig.emailsmtp,
                        sysConfig.emailssl,
                        sysConfig.emailusername,
                        AESEncryptHelper.Decode(sysConfig.emailpassword, sysConfig.sysencryptstring),
                        sysConfig.emailnickname,
                        sysConfig.emailfrom,
                        model.email,
                        titletxt, bodytxt);
                }
                catch
                {
                    context.Result = Content("{\"status\":0, \"msg\":\"邮件发送失败，请联系本站管理员！\"}");
                    return;
                }
                context.Result = Content("{\"status\":1, \"msg\":\"邮件发送成功，请登录邮箱查看邮件！\"}");
                return;
                #endregion
            }
            context.Result = Content("{\"status\":0, \"msg\":\"发生未知错误，请检查参数是否正确！\"}");
            return;
        }
        #endregion

        #region 用户重设密码OK=================================
        private void user_repassword(ActionExecutingContext context)
        {
            string strcode = Request.Form["hideCode"]; //取回密码字符串
            string password = Request.Form["txtPassword"]; //重设后的密码

            //检查验证字符串
            if (string.IsNullOrEmpty(strcode))
            {
                context.Result = Content("{\"status\":0, \"msg\":\"对不起，校检码字符串不能为空！\"}");
                return;
            }
            //检查输入的新密码
            if (string.IsNullOrEmpty(password))
            {
                context.Result = Content("{\"status\":0, \"msg\":\"对不起，请输入您的新密码！\"}");
                return;
            }

            User_code codeModel = _user_code.GetModel(strcode);
            if (codeModel == null)
            {
                context.Result = Content("{\"status\":0, \"msg\":\"对不起，校检码不存在或已过期！\"}");
                return;
            }
            //验证用户是否存在
            if (!_users.Exists(codeModel.user_id))
            {
                context.Result = Content("{\"status\":0, \"msg\":\"对不起，该用户不存在或已被删除！\"}");
                return;
            }
            Users userModel = _users.GetModel(codeModel.user_id);
            //执行修改操作
            userModel.password = AESEncryptHelper.Encode(password, userModel.salt);
            _users.Update(userModel);
            //更改验证字符串状态
            codeModel.count = 1;
            codeModel.status = 1;
            _user_code.Update(codeModel);
            context.Result = Content("{\"status\":1, \"msg\":\"修改密码成功，请记住新密码！\", \"url\":\""
                       + "/Web/Login/Index\"}");
            return;
        }
        #endregion

        #region 申请邀请码OK===================================
        private void user_invite_code(ActionExecutingContext context)
        {
            //检查用户是否登录
            Users model = GetUserInfo();
            if (model == null)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，用户尚未登录或已超时！\"}");
                return;
            }
            //检查是否开启邀请注册
            if (userConfig.regstatus != 4)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，系统不允许通过邀请注册！\"}");
                return;
            }
            //检查申请是否超过限制
            if (userConfig.invitecodenum > 0)
            {
                int result = _user_code.GetCount("where user_name='" + model.user_name + "' and type='" + CMSEnums.CodeEnum.Register.ToString() + "' and datediff(d,add_time,getdate())=0");
                if (result >= userConfig.invitecodenum)
                {
                    context.Result=Content("{\"status\":0, \"msg\":\"对不起，您申请邀请码的数量已超过每天限制！\"}");
                    return;
                }
            }
            //删除过期的邀请码
            _user_code.Delete("where type='" + CMSEnums.CodeEnum.Register.ToString() + "' and status=1 or datediff(d,eff_time,getdate())>0");
            //随机取得邀请码
            string str_code = Utils.GetCheckCode(8);
            User_code codeModel = new User_code();
            codeModel.user_id = model.id;
            codeModel.user_name = model.user_name;
            codeModel.type = CMSEnums.CodeEnum.Register.ToString();
            codeModel.str_code = str_code;
            codeModel.user_ip = CMSRequest.GetClientUserIp(context.HttpContext);
            if (userConfig.invitecodeexpired > 0)
            {
                codeModel.eff_time = DateTime.Now.AddDays(userConfig.invitecodeexpired);
            }
            else
            {
                codeModel.eff_time = DateTime.Now.AddDays(1);
            }
            _user_code.Add(codeModel);
            context.Result=Content("{\"status\":1, \"msg\":\"恭喜您，申请邀请码已成功！\"}");
            return;
        }
        #endregion

        #region 用户兑换积分OK=================================
        private void user_point_convert(ActionExecutingContext context)
        {
            //检查系统是否启用兑换积分功能
            if (userConfig.pointcashrate == 0)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，网站未开启兑换积分功能！\"}");
                return;
            }
            //检查用户是否登录
            Users model = GetUserInfo();
            if (model == null)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，用户尚未登录或已超时！\"}");
                return;
            }
            int amout = 0;
            int.TryParse(Request.Query["txtAmount"],out amout);
            string password = Request.Form["txtPassword"];
            if (model.amount < 1)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，您账户上的余额不足！\"}");
                return;
            }
            if (amout < 1)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，最小兑换金额为1元！\"}");
                return;
            }
            if (amout > model.amount)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，您兑换的金额大于账户余额！\"}");
                return;
            }
            if (password == "")
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，请输入您账户的密码！\"}");
                return;
            }
            //验证密码
            if (AESEncryptHelper.Encode(password, model.salt) != model.password)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，您输入的密码不正确！\"}");
                return;
            }
            //计算兑换后的积分值
            int convertPoint = (int)(Convert.ToDecimal(amout) * userConfig.pointcashrate);
            //扣除金额
            int amountNewId = _user_amount_log.Add(model.id, model.user_name, amout * -1, "用户兑换积分");
            //增加积分
            if (amountNewId < 1)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"转换过程中发生错误，请重新提交！\"}");
                return;
            }
            int pointNewId = _user_point_log.Add(model.id, model.user_name, convertPoint, "用户兑换积分", true);
            if (pointNewId < 1)
            {
                //返还金额
                _user_amount_log.Add(model.id, model.user_name, amout, "用户兑换积分失败，返还金额");
                context.Result=Content("{\"status\":0, \"msg\":\"转换过程中发生错误，请重新提交！\"}");
                return;
            }

            context.Result=Content("{\"status\":1, \"msg\":\"恭喜您，积分兑换成功！\"}");
            return;
        }
        #endregion

        #region 用户在线充值OK=================================
        private void user_amount_recharge(ActionExecutingContext context)
        {
            //检查用户是否登录
            Users model = GetUserInfo();
            if (model == null)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，用户尚未登录或已超时！\"}");
                return;
            }
            decimal amount = CMSRequest.GetFormDecimal("order_amount", 0,context.HttpContext);
            int payment_id = CMSRequest.GetFormInt("payment_id", context.HttpContext);
            if (amount == 0)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，请输入正确的充值金额！\"}");
                return;
            }
            if (payment_id == 0)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，请选择正确的支付方式！\"}");
                return;
            }
            if (!_site_payment.Exists(payment_id))
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，支付方式不存在或已删除！\"}");
                return;
            }
            payment_id = _site_payment.GetModel(payment_id).payment_id;
            //生成订单号
            string order_no = "R" + Utils.GetOrderNumber(); //订单号R开头为充值订单
            _user_recharge.Add(model.id, model.user_name, order_no, payment_id, amount);
            //保存成功后返回订单号
            context.Result=Content("{\"status\":1, \"msg\":\"订单保存成功！\", \"url\":\""
                + "payment?action=confirm&order_no=" + order_no + "\"}");
            return;

        }
        #endregion

        #region 用户向商家付款OK=================================
        private void user_cash_pay(ActionExecutingContext context)
        {
            //检查用户是否登录
            Users model = GetUserInfo();
            if (model == null)
            {
                context.Result = Content("{\"status\":0, \"msg\":\"对不起，用户尚未登录或已超时！\"}");
                return;
            }
            decimal amount = CMSRequest.GetFormDecimal("order_amount", 0, context.HttpContext);
            int shop_id = CMSRequest.GetFormInt("shop_id",0, context.HttpContext);
            int payment_id = CMSRequest.GetFormInt("payment_id", context.HttpContext);//1奖金，2重消
            if (amount == 0)
            {
                context.Result = Content("{\"status\":0, \"msg\":\"对不起，请输入正确的充值金额！\"}");
                return;
            }
            if (payment_id == 0)
            {
                context.Result = Content("{\"status\":0, \"msg\":\"对不起，请选择正确的支付方式！\"}");
                return;
            }
            var shop = _shop.GetModel(shop_id);
            if (shop==null)
            {
                context.Result = Content("{\"status\":0, \"msg\":\"对不起，你要支付的商户不存在！\"}");
                return;
            }
            if (shop.is_lock==1)
            {
                context.Result = Content("{\"status\":0, \"msg\":\"对不起，你要支付的商户已锁定！\"}");
                return;
            }
            if(model.cash_point< amount&&payment_id==1||model.shop_point<amount&&payment_id==2)
            {
                context.Result = Content("{\"status\":0, \"msg\":\"对不起，金额不足！\"}");
                return;
            }
            var flag=_shop_bills.Add(model.id, shop_id, amount, payment_id);
            if(!flag)
            {
                context.Result = Content("{\"status\":0, \"msg\":\"对不起，金额不足支付失败！\"}");
                return;
            }
            //保存成功后返回订单号
            context.Result = Content("{\"status\":1, \"msg\":\"支付成功！\", \"url\":\""
                + "/web/payment?action=succeed&order_no=P\"}");
            return;

        }
        #endregion

        #region 发布站内短消息OK===============================
        private void user_message_add(ActionExecutingContext context)
        {
            //检查用户是否登录
            Users model = GetUserInfo();
            if (model == null)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，用户尚未登录或已超时！\"}");
                return;
            }
            string code = Request.Form["txtCode"];
            string send_save = Request.Form["sendSave"];
            string user_name = Request.Form["txtUserName"];
            string title = Request.Form["txtTitle"];
            string content = Request.Form["txtContent"];
            //校检验证码
            string result = verify_code(context, code);
            if (result != "success")
            {
                context.Result=Content(result);
                return;
            }
            //检查用户名
            if (string.IsNullOrEmpty(user_name) || !_users.Exists(user_name))
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，该用户不存在或已删除！\"}");
                return;
            }
            //检查标题
            if (string.IsNullOrEmpty(title))
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，请输入短消息标题！\"}");
                return;
            }
            //检查内容
            if (string.IsNullOrEmpty(content))
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，请输入短消息内容！\"}");
                return;
            }
            //保存数据
            User_message modelMessage = new User_message();
            modelMessage.type = 2;
            modelMessage.post_user_name = model.user_name;
            modelMessage.accept_user_name = user_name;
            modelMessage.title = title;
            modelMessage.content = content;
            _user_message.Add(modelMessage);
            if (send_save == "true") //保存到收件箱
            {
                modelMessage.type = 3;
                _user_message.Add(modelMessage);
            }
            context.Result=Content("{\"status\":1, \"msg\":\"发布短信息成功！\"}");
            return;
        }
        #endregion

        #region 编辑用户收货地址OK=============================
        private void user_address_edit(ActionExecutingContext context)
        {
            //检查用户是否登录
            Users userModel = GetUserInfo();
            User_addr_book model = new User_addr_book();
            if (userModel == null)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，用户尚未登录或已超时！\"}");
                return;
            }
            int id = 0;
            int.TryParse(Request.Query["id"], out id);
            if (id > 0)
            {
                if (!_user_addr_book.Exists(id, userModel.user_name))
                {
                    context.Result=Content("{\"status\":0, \"msg\":\"对不起，收货地址不存在或已删除！\"}");
                    return;
                }
                model = _user_addr_book.GetModel(id);
            }
            string code = Request.Form["txtCode"];
            string accept_name = Request.Form["txtAcceptName"];
            string province = Request.Form["txtProvince"];
            string city = Request.Form["txtCity"];
            string area = Request.Form["txtArea"];
            string address = Request.Form["txtAddress"];
            string mobile = Request.Form["txtMobile"];
            string telphone = Request.Form["txtTelphone"];
            string email = Request.Form["txtEmail"];
            string post_code = Request.Form["txtPostCode"];

            //校检验证码
            string result = verify_code(context, code);
            if (result != "success")
            {
                context.Result=Content(result);
                return;
            }
            //检查收件人
            if (string.IsNullOrEmpty(accept_name))
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，请输入收件人姓名！\"}");
                return;
            }
            //检查省市区
            if (string.IsNullOrEmpty(province) || string.IsNullOrEmpty(city) || string.IsNullOrEmpty(area))
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，请选择您所在的省市区！\"}");
                return;
            }
            //检查手机
            if (string.IsNullOrEmpty(mobile))
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，请输入收件人的手机！\"}");
                return;
            }
            //保存数据
            model.user_id = userModel.id;
            model.user_name = userModel.user_name;
            model.accept_name = accept_name;
            model.area = province + "," + city + "," + area;
            model.address = address;
            model.mobile = mobile;
            model.telphone = telphone;
            model.email = email;
            model.post_code = post_code;
            if (id > 0)
            {
                _user_addr_book.Update(model);
                context.Result=Content("{\"status\":1, \"msg\":\"修改收货地址成功！\"}");
            }
            else
            {
                _user_addr_book.Add(model);
                context.Result=Content("{\"status\":1, \"msg\":\"新增收货地址成功！\"}");
            }
            return;
        }
        #endregion

        #region 用户设置默认收货地址OK=========================
        private void user_address_default(ActionExecutingContext context)
        {
            //检查用户是否登录
            Users userModel = GetUserInfo();
            if (userModel == null)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，用户尚未登录或已超时！\"}");
                return;
            }
            int id=CMSRequest.GetInt("id",0,context.HttpContext);
            if (_user_addr_book.Exists(id, userModel.user_name))
            {
                _user_addr_book.SetDefault(id, userModel.user_name);
                context.Result=Content("{\"status\":1, \"msg\":\"默认收货地址设置成功！\"}");
                return;
            }
            context.Result=Content("{\"status\":0, \"msg\":\"对不起，该记录不存在或已删除！\"}");
            return;
        }
        #endregion

        #region 删除用户积分明细OK=============================
        private void user_point_delete(ActionExecutingContext context)
        {
            //检查用户是否登录
            Users model = GetUserInfo();
            if (model == null)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，用户尚未登录或已超时！\"}");
                return;
            }
            string check_id = Request.Form["checkId"];
            if (string.IsNullOrEmpty(check_id))
            {
                context.Result=Content("{\"status\":0, \"msg\":\"删除失败，请检查传输参数！\"}");
                return;
            }
            string[] arrId = check_id.Split(',');
            for (int i = 0; i < arrId.Length; i++)
            {
                int id = Utils.StrToInt(arrId[i], 0);
                if (id > 0)
                {
                    _user_point_log.Delete(id, model.user_name);
                }
            }
            context.Result=Content("{\"status\":1, \"msg\":\"积分明细删除成功！\"}");
            return;
        }
        #endregion

        #region 删除用户收支明细OK=============================
        private void user_amount_delete(ActionExecutingContext context)
        {
            //检查用户是否登录
            Users model = GetUserInfo();
            if (model == null)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，用户尚未登录或已超时！\"}");
                return;
            }
            string check_id = Request.Form["checkId"];
            if (string.IsNullOrEmpty(check_id))
            {
                context.Result=Content("{\"status\":0, \"msg\":\"删除失败，请检查传输参数！\"}");
                return;
            }
            string[] arrId = check_id.Split(',');
            for (int i = 0; i < arrId.Length; i++)
            {
                int id = Utils.StrToInt(arrId[i], 0);
                if (id > 0)
                {
                    _user_amount_log.Delete(id, model.user_name);
                }
            }
            context.Result=Content("{\"status\":1, \"msg\":\"收支明细删除成功！\"}");
            return;
        }
        #endregion

        #region 删除用户充值记录OK=============================
        private void user_recharge_delete(ActionExecutingContext context)
        {
            //检查用户是否登录
            Users model = GetUserInfo();
            if (model == null)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，用户尚未登录或已超时！\"}");
                return;
            }
            string check_id = Request.Form["checkId"];
            if (string.IsNullOrEmpty(check_id))
            {
                context.Result=Content("{\"status\":0, \"msg\":\"删除失败，请检查传输参数！\"}");
                return;
            }
            string[] arrId = check_id.Split(',');
            for (int i = 0; i < arrId.Length; i++)
            {
                int id = Utils.StrToInt(arrId[i], 0);
                if (id > 0)
                {
                    _user_recharge.Delete(id, model.user_name);
                }
            }
            context.Result=Content("{\"status\":1, \"msg\":\"充值记录删除成功！\"}");
            return;
        }
        #endregion

        #region 删除短消息OK===================================
        private void user_message_delete(ActionExecutingContext context)
        {
            //检查用户是否登录
            Users model = GetUserInfo();
            if (model == null)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，用户尚未登录或已超时！\"}");
                return;
            }
            string check_id = Request.Form["checkId"];
            if (string.IsNullOrEmpty(check_id))
            {
                context.Result=Content("{\"status\":0, \"msg\":\"删除失败，请检查传输参数！\"}");
                return;
            }
            string[] arrId = check_id.Split(',');
            for (int i = 0; i < arrId.Length; i++)
            {
                int id = Utils.StrToInt(arrId[i], 0);
                if (id > 0)
                {
                    _user_message.Delete(id, model.user_name);
                }
            }
            context.Result=Content("{\"status\":1, \"msg\":\"删除短消息成功！\"}");
            return;
        }
        #endregion

        #region 删除用户收货地址OK=============================
        private void user_address_delete(ActionExecutingContext context)
        {
            //检查用户是否登录
            Users model = GetUserInfo();
            if (model == null)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，用户尚未登录或已超时！\"}");
                return;
            }
            string check_id = Request.Form["checkId"];
            if (string.IsNullOrEmpty(check_id))
            {
                context.Result=Content("{\"status\":0, \"msg\":\"删除失败，请检查传输参数！\"}");
                return;
            }
            string[] arrId = check_id.Split(',');
            for (int i = 0; i < arrId.Length; i++)
            {
                int id = Utils.StrToInt(arrId[i], 0);
                if (id > 0)
                {
                    _user_addr_book.Delete(id, model.user_name);
                }
            }
            context.Result=Content("{\"status\":1, \"msg\":\"删除收货地址成功！\"}");
            return;
        }
        #endregion

        #region 获取对应的商品信息OK===========================
        private void get_article_goods_info(ActionExecutingContext context)
        {
            int channel_id = CMSRequest.GetInt("channel_id", 0,context.HttpContext);
            int article_id = CMSRequest.GetInt("article_id", 0, context.HttpContext);
            string spec_ids = CMSRequest.GetString("ids", context.HttpContext);
            if (channel_id == 0 || article_id == 0)
            {
                context.Result = Content("{\"status\": 0, \"msg\": \"对不起，传输参数不正确！\"}");
                return;
            }
            if (string.IsNullOrEmpty(spec_ids))
            {
                context.Result=Content("{\"status\": 0, \"msg\": \"对不起，传输参数不正确！\"}");
                return;
            }
            //查询商品信息
            Article_goods goodsModel = _article_goods.GetModel(article_id, spec_ids);
            if (goodsModel == null)
            {
                context.Result=Content("{\"status\": 0, \"msg\": \"对不起，暂无查到商品信息！\"}");
                return;
            }
            //查询是否登录，有则查询会员价格
            Users userModel = GetUserInfo();
            if (userModel != null)
            {
                //查询会员组价格
                User_group_price userPriceModel = _user_group_price.GetModel(goodsModel.id, userModel.group_id);
                if (userPriceModel != null)
                {
                    goodsModel.sell_price = userPriceModel.price;
                }
                else
                {
                    //查询会员组折扣
                    User_groups groupModel = _user_groups.GetModel(userModel.group_id);
                    if (groupModel != null)
                    {
                        goodsModel.sell_price = goodsModel.sell_price * groupModel.discount / 100;
                    }
                }
            }
            //以JSON格式输出商品信息
            context.Result=Content("{\"status\": \"1\", \"id\": \"" + goodsModel.id + "\", \"article_id\": \"" + goodsModel.article_id + "\", \"goods_id\": \"" + goodsModel.id
                + "\", \"goods_no\": \"" + goodsModel.goods_no + "\", \"spec_ids\": \"" + goodsModel.spec_ids + "\", \"spec_text\": \"" + goodsModel.spec_text
                + "\", \"stock_quantity\": \"" + goodsModel.stock_quantity + "\", \"market_price\": \"" + goodsModel.market_price + "\", \"sell_price\": \"" + goodsModel.sell_price + "\"}");
        }
        #endregion

        #region 购物车加入商品OK===============================
        private void cart_goods_add(ActionExecutingContext context)
        {
            int channel_id = CMSRequest.GetInt("channel_id", 0,context.HttpContext);
            int shop_id = CMSRequest.GetInt("shop_id", 0,context.HttpContext);
            int article_id = CMSRequest.GetFormInt("article_id", 0, context.HttpContext);
            int goods_id = CMSRequest.GetFormInt("goods_id", 0, context.HttpContext);
            int quantity = CMSRequest.GetFormInt("quantity", 1, context.HttpContext);
            if (channel_id == 0 || article_id == 0)
            {
                context.Result = Content("{\"status\":0, \"msg\":\"您提交的商品参数有误！\"}");
                return;
            }
            //检查商品是否正确
            if (goods_id > 0 && !_article_goods.Exists(article_id, goods_id))
            {
                context.Result=Content("{\"status\":0, \"msg\":\"您提交的商品参数有误！\"}");
                return;
            }
            //查找会员组
            int group_id = 0;
            Users groupModel = GetUserInfo();
            if (groupModel != null)
            {
                group_id = groupModel.group_id;
            }
            //统计购物车
            shopcart.Add(article_id, goods_id, quantity,shop_id);
            cart_total nowModel = shopcart.GetNow(article_id, goods_id, quantity, group_id);
            cart_total cartModel = shopcart.GetTotal(group_id);
            context.Result=Content("{\"status\":1, \"msg\":\"商品已成功添加到购物车！\", \"quantity\":" + (cartModel.total_quantity+ nowModel.total_quantity) + ", \"amount\":" + (cartModel.real_amount + nowModel.real_amount) + "}"); //.net转向.netcore cookie不能立马得到
            return;
        }
        #endregion

        #region 加入结账商品OK=================================
        private void cart_goods_buy(ActionExecutingContext context)
        {
            string jsonData = CMSRequest.GetFormString("jsondata",context.HttpContext);
            if (string.IsNullOrEmpty(jsonData))
            {
                context.Result=Content("{\"status\":0, \"msg\":\"商品传输参数不正确！\"}");
                return;
            }
            List<cart_keys> ls = (List<cart_keys>)JsonHelper.JSONToObject<List<cart_keys>>(jsonData);
            if (ls != null)
            {
                HttpContext.Response.Cookies.Append(CMSKeys.COOKIE_SHOPPING_BUY, jsonData); //暂放在清单
                context.Result=Content("{\"status\":1, \"msg\":\"商品已成功加入购物清单！\"}");
                return;
            }
            context.Result=Content("{\"status\":0, \"msg\":\"商品数据传输不正确！\"}");
            return;
        }
        #endregion

        #region 修改购物车商品OK===============================
        private void cart_goods_update(ActionExecutingContext context)
        {
            int channel_id = CMSRequest.GetInt("channel_id", 0,context.HttpContext);
            int article_id = CMSRequest.GetFormInt("article_id", 0, context.HttpContext);
            int goods_id = CMSRequest.GetFormInt("goods_id", 0, context.HttpContext);
            int quantity = CMSRequest.GetFormInt("quantity", 0, context.HttpContext);
            if (channel_id == 0 || article_id == 0)
            {
                context.Result = Content("{\"status\":0, \"msg\":\"您提交的商品参数有误！\"}");
                return;
            }
            if (quantity == 0)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"购买数量不能小于1！\"}");
                return;
            }
            
            cart_keys model = shopcart.Update(article_id, goods_id, quantity);
            if (model != null)
            {
                context.Result=Content("{\"status\":1, \"msg\":\"商品数量修改成功！\", \"channel_id\":" + model.channel_id + ", \"article_id\":" + model.article_id + ", \"goods_id\":" + model.goods_id + ", \"quantity\":" + model.quantity + "}");
                return;
            }
            context.Result=Content("{\"status\":0, \"msg\":\"更新失败，请检查操作是否有误！\"}");
            return;
        }
        #endregion

        #region 删除购物车商品OK===============================
        private void cart_goods_delete(ActionExecutingContext context)
        {
            int clear = CMSRequest.GetFormInt("clear", 0,context.HttpContext);
            int channel_id = CMSRequest.GetInt("channel_id", 0, context.HttpContext);
            int article_id = CMSRequest.GetFormInt("article_id", 0, context.HttpContext);
            int goods_id = CMSRequest.GetFormInt("goods_id", 0, context.HttpContext);
            if (clear == 1)
            {
                shopcart.Clear(); //清空购物车
                context.Result=Content("{\"status\":1, \"msg\":\"购物车清空成功！\"}");
                return;
            }
            if (article_id == 0)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"您提交的商品参数有误！\"}");
                return;
            }
            shopcart.Clear(article_id, goods_id);
            context.Result=Content("{\"status\":1, \"msg\":\"商品移除成功！\"}");
            return;
        }
        #endregion

        #region 保存购物订单OK=================================
        private void order_save(ActionExecutingContext context)
        {
            //获取传参信息===================================
            string hideGoodsJson =HttpContext.Request.Cookies[CMSKeys.COOKIE_SHOPPING_BUY]; //获取商品JSON数据
            int book_id = CMSRequest.GetFormInt("book_id", 1,context.HttpContext);
            int payment_id = CMSRequest.GetFormInt("payment_id", context.HttpContext);
            int express_id = CMSRequest.GetFormInt("express_id", context.HttpContext);
            int is_invoice = CMSRequest.GetFormInt("is_invoice", 0, context.HttpContext);
            string accept_name = Utils.ToHtml(CMSRequest.GetFormString("accept_name", context.HttpContext));
            string province = Utils.ToHtml(CMSRequest.GetFormString("province", context.HttpContext));
            string city = Utils.ToHtml(CMSRequest.GetFormString("city", context.HttpContext));
            string area = Utils.ToHtml(CMSRequest.GetFormString("area", context.HttpContext));
            string address = Utils.ToHtml(CMSRequest.GetFormString("address", context.HttpContext));
            string telphone = Utils.ToHtml(CMSRequest.GetFormString("telphone", context.HttpContext));
            string mobile = Utils.ToHtml(CMSRequest.GetFormString("mobile", context.HttpContext));
            string email = Utils.ToHtml(CMSRequest.GetFormString("email", context.HttpContext));
            string post_code = Utils.ToHtml(CMSRequest.GetFormString("post_code", context.HttpContext));
            string message = Utils.ToHtml(CMSRequest.GetFormString("message", context.HttpContext));
            string invoice_title = Utils.ToHtml(CMSRequest.GetFormString("invoice_title", context.HttpContext));

            //检查传参信息===================================
            if (string.IsNullOrEmpty(hideGoodsJson))
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，无法获取商品信息！\"}");
                return;
            }
            if (express_id == 0)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，请选择配送方式！\"}");
                return;
            }
            if (payment_id == 0)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，请选择支付方式！\"}");
                return;
            }
            Express expModel = _express.GetModel(express_id);
            if (expModel == null)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，配送方式不存在或已删除！\"}");
                return;
            }
            //检查支付方式
            Payment payModel = _payment.GetModel(payment_id);
            if (payModel == null)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，支付方式不存在或已删除！\"}");
                return;
            }
            //检查收货人
            if (string.IsNullOrEmpty(accept_name))
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，请输入收货人姓名！\"}");
                return;
            }
            //检查手机和电话
            if (string.IsNullOrEmpty(telphone) && string.IsNullOrEmpty(mobile))
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，请输入收货人联系电话或手机！\"}");
                return;
            }
            //检查地区
            if (string.IsNullOrEmpty(province) && string.IsNullOrEmpty(city))
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，请选择您所在的省市区！\"}");
                return;
            }
            //检查地址
            if (string.IsNullOrEmpty(address))
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，请输入详细的收货地址！\"}");
                return;
            }
            //如果开启匿名购物则不检查会员是否登录
            int user_id = 0;
            int user_group_id = 0;
            string user_name = string.Empty;
            //检查用户是否登录
            Users userModel = GetUserInfo();
            if (userModel != null)
            {
                user_id = userModel.id;
                user_group_id = userModel.group_id;
                user_name = userModel.user_name;
                //检查是否需要添加会员地址
                if (book_id == 0)
                {
                    User_addr_book addrModel = new User_addr_book();
                    addrModel.user_id = userModel.id;
                    addrModel.user_name = userModel.user_name;
                    addrModel.accept_name = accept_name;
                    addrModel.area = province + "," + city + "," + area;
                    addrModel.address = address;
                    addrModel.mobile = mobile;
                    addrModel.telphone = telphone;
                    addrModel.email = email;
                    addrModel.post_code = post_code;
                    _user_addr_book.Add(addrModel);
                }
            }
            if (orderConfig.anonymous == 0 && userModel == null)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，用户尚未登录或已超时！\"}");
                return;
            }
            //获取商品信息==================================
            List<cart_keys> iList = (List<cart_keys>)JsonHelper.JSONToObject<List<cart_keys>>(hideGoodsJson);
            //检查商品是否同一家shop_id
            #region 检查商品是否同一家shop_id
            int supply = iList.Select(a => a.shop_id).Distinct().Count();
            if (supply > 1)
            {
                context.Result = Content("{\"status\":0, \"msg\":\"对不起，每个订单只能有同一家商品！\"}");
                return;
            } 
            #endregion
            List<cart_items> goodsList = shopcart.ToList(iList, user_group_id); //商品列表
            cart_total goodsTotal = shopcart.GetTotal(goodsList); //商品统计
            if (goodsList == null)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，商品为空，无法结算！\"}");
                return;
            }
            //如果积分换购，检查一下用户积分是否足够扣减
            if (goodsTotal.total_point < 0 && userModel.point < (goodsTotal.total_point * -1))
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，您的账户积分不足，无法结算！\"}");
                return;
            }
            //保存订单=======================================
            Orders model = new Orders();
            model.shop_id = iList.Select(a => a.shop_id).FirstOrDefault();
            model.order_no = "B" + Utils.GetOrderNumber(); //订单号B开头为商品订单
            model.user_id = user_id;
            model.user_name = user_name;
            model.payment_id = payment_id;
            model.express_id = express_id;
            model.accept_name = accept_name;
            model.area = province + "," + city + "," + area; //省市区以逗号相隔
            model.address = address;
            model.telphone = telphone;
            model.mobile = mobile;
            model.message = message;
            model.email = email;
            model.post_code = post_code;
            model.is_invoice = is_invoice;
            model.payable_amount = goodsTotal.payable_amount;
            model.real_amount = goodsTotal.real_amount;
            model.pv_amount = goodsTotal.pv_amount;
            model.express_status = 1;
            model.express_fee = expModel.express_fee; //物流费用
                                                      //是否先款后货
            if (payModel.type == 1)
            {
                model.payment_status = 1; //标记未付款
                if (payModel.poundage_type == 1 && payModel.poundage_amount > 0) //百分比
                {
                    model.payment_fee = model.real_amount * payModel.poundage_amount / 100;
                }
                else //固定金额
                {
                    model.payment_fee = payModel.poundage_amount;
                }
            }
            //是否开具发票
            if (model.is_invoice == 1)
            {
                model.invoice_title = invoice_title;
                if (orderConfig.taxtype == 1 && orderConfig.taxamount > 0) //百分比
                {
                    model.invoice_taxes = model.real_amount * orderConfig.taxamount / 100;
                }
                else //固定金额
                {
                    model.invoice_taxes = orderConfig.taxamount;
                }
            }
            //订单总金额=实付商品金额+运费+支付手续费+税金
            model.order_amount = model.real_amount + model.express_fee + model.payment_fee + model.invoice_taxes;
            //购物积分,可为负数
            model.point = goodsTotal.total_point;
            model.add_time = DateTime.Now;
            //商品详细列表
            List<Order_goods> gls = new List<Order_goods>();
            foreach (cart_items item in goodsList)
            {
                //检查库存数量
                if (_article.GetStockQuantity(item.article_id, item.goods_id) < item.quantity)
                {
                    context.Result=Content("{\"status\":0, \"msg\":\"订单中某个商品库存不足，请修改重试！\"}");
                    return;
                }
                //添加进订单列表
                gls.Add(new Order_goods
                {
                    shop_id = item.shop_id,
                    article_id = item.article_id,
                    goods_id = item.goods_id,
                    goods_no = item.goods_no,
                    goods_title = item.title,
                    img_url = item.img_url,
                    spec_text = item.spec_text,
                    goods_price = item.sell_price,
                    goods_pv_price = item.pv_price,
                    real_price = item.user_price,
                    real_pv_price=item.user_pv_price,
                    quantity = item.quantity,
                    point = item.point
                }); ;
            }
            model.order_goods = gls;
            int result = _orders.Add(model);
            if (result < 1)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"订单保存发生错误，请联系管理员！\"}");
                return;
            }
            //扣除积分
            if (model.point < 0)
            {
                _user_point_log.Add(model.user_id, model.user_name, model.point, "积分换购，订单号：" + model.order_no, false);
            }
            //删除购物车对应的商品
            shopcart.Clear(iList);
            //清空结账清单
            HttpContext.Response.Cookies.Delete(CMSKeys.COOKIE_SHOPPING_BUY);
            //提交成功，返回URL
            context.Result=Content("{\"status\":1, \"url\":\""
                + "Payment/Index?action=confirm&order_no=" + model.order_no + "\", \"msg\":\"恭喜您，订单已成功提交！\"}");
            return;
        }
        #endregion

        #region 用户取消订单OK=================================
        private void order_cancel(ActionExecutingContext context)
        {
            //检查用户是否登录
            Users userModel = GetUserInfo();
            if (userModel == null)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，用户尚未登录或已超时！\"}");
                return;
            }
            //检查订单是否存在
            string order_no = Request.Query["order_no"];
            Orders orderModel = _orders.GetModel(order_no);
            if (order_no == "" || orderModel == null)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，订单号不存在或已删除！\"}");
                return;
            }
            //检查是否自己的订单
            if (userModel.id != orderModel.user_id)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，不能取消别人的订单状态！\"}");
                return;
            }
            //检查订单状态
            if (orderModel.status > 1)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，订单不是生成状态，不能取消！\"}");
                return;
            }
            bool result = _orders.UpdateField(order_no, "status=4");
            if (!result)
            {
                context.Result=Content("{\"status\":0, \"msg\":\"对不起，操作过程中发生不可遇知的错误！\"}");
                return;
            }
            //如果是积分换购则返还积分
            if (orderModel.point < 0)
            {
                _user_point_log.Add(orderModel.user_id, orderModel.user_name, -1 * orderModel.point, "取消订单，返还换购积分，订单号：" + orderModel.order_no, false);
            }
            context.Result=Content("{\"status\":1, \"msg\":\"取消订单成功！\"}");
            return;
        }
        #endregion        

        #region 修改订单收货地址OK=================================
        private void edit_order_address(ActionExecutingContext context)
        {
            //获取传参信息===================================
            int order_id = CMSRequest.GetFormInt("order_id", 0, context.HttpContext);                   
            string accept_name = Utils.ToHtml(CMSRequest.GetFormString("accept_name", context.HttpContext));
            string province = Utils.ToHtml(CMSRequest.GetFormString("province", context.HttpContext));
            string city = Utils.ToHtml(CMSRequest.GetFormString("city", context.HttpContext));
            string area = Utils.ToHtml(CMSRequest.GetFormString("area", context.HttpContext));
            string address = Utils.ToHtml(CMSRequest.GetFormString("address", context.HttpContext));
            string telphone = Utils.ToHtml(CMSRequest.GetFormString("telphone", context.HttpContext));
            string mobile = Utils.ToHtml(CMSRequest.GetFormString("mobile", context.HttpContext));
            string email = Utils.ToHtml(CMSRequest.GetFormString("email", context.HttpContext));
            string post_code = Utils.ToHtml(CMSRequest.GetFormString("post_code", context.HttpContext));
            //检查收货人
            if (string.IsNullOrEmpty(accept_name))
            {
                context.Result = Content("{\"status\":0, \"msg\":\"对不起，请输入收货人姓名！\"}");
                return;
            }
            //检查手机和电话
            if (string.IsNullOrEmpty(telphone) && string.IsNullOrEmpty(mobile))
            {
                context.Result = Content("{\"status\":0, \"msg\":\"对不起，请输入收货人联系电话或手机！\"}");
                return;
            }
            //检查地区
            if (string.IsNullOrEmpty(province) && string.IsNullOrEmpty(city))
            {
                context.Result = Content("{\"status\":0, \"msg\":\"对不起，请选择您所在的省市区！\"}");
                return;
            }
            //检查地址
            if (string.IsNullOrEmpty(address))
            {
                context.Result = Content("{\"status\":0, \"msg\":\"对不起，请输入详细的收货地址！\"}");
                return;
            }
            var order = _orders.GetModel(order_id);
            if(order==null)
            {
                context.Result = Content("{\"status\":0, \"msg\":\"对不起，订单不存在！\"}");
                return;
            }
            //检查用户是否登录
            Users userModel = GetUserInfo();
            if (userModel == null)
            {
                context.Result = Content("{\"status\":0, \"msg\":\"对不起，用户尚未登录或已超时！\"}");
                return;
            }
            if (order.user_id!= userModel.id)
            {
                context.Result = Content("{\"status\":0, \"msg\":\"对不起，不是自己的订单！\"}");
                return;
            }
            //修改订单=======================================        
            order.accept_name = accept_name;
            order.area = province + "," + city + "," + area; //省市区以逗号相隔
            order.address = address;
            order.telphone = telphone;
            order.mobile = mobile;          
            order.email = email;
            order.post_code = post_code;
            string updateStr = "accept_name='"+order.accept_name+ "',area='" + order.area+ "',address='" + order.address+ "',telphone='" + order.telphone+ "',mobile='" + order.mobile+ "',email='" + order.email + "',post_code='" + order.post_code + "'";
            _orders.UpdateField(order.id, updateStr);         
           
            //提交成功，返回URL
            context.Result = Content("{\"status\":1, \"url\":\""
                + "/Web/UserOrder/Index\", \"msg\":\"恭喜您，订单已成功修改！\"}");
            return;
        }
        #endregion

        #region 通用外理方法=================================

        #region 校检网站验证码OK===============================
        private string verify_code(ActionExecutingContext context, string strcode)
        {
            if (string.IsNullOrEmpty(strcode))
            {
                return "{\"status\":0, \"msg\":\"对不起，请输入验证码！\"}";
            }
            if (context.HttpContext.Session.GetString(CMSKeys.SESSION_CODE) == null)
            {
                return "{\"status\":0, \"msg\":\"对不起，验证码超时或已过期！\"}";
            }
            if (strcode.ToLower() != (context.HttpContext.Session.GetString(CMSKeys.SESSION_CODE)).ToLower())
            {
                return "{\"status\":0, \"msg\":\"您输入的验证码与系统的不一致！\"}";
            }
            context.HttpContext.Session.Remove(CMSKeys.SESSION_CODE);
            return "success";
        }
        #endregion

        #region 校检手机验证码OK===============================
        private string verify_sms_code(ActionExecutingContext context, string strcode)
        {
            if (string.IsNullOrEmpty(strcode))
            {
                return "{\"status\":0, \"msg\":\"对不起，请输入验证码！\"}";
            }
            if (context.HttpContext.Session.GetString(CMSKeys.SESSION_SMS_CODE) == null)
            {
                return "{\"status\":0, \"msg\":\"对不起，验证码超时或已过期！\"}";
            }
            if (strcode.ToLower() != (context.HttpContext.Session.GetString(CMSKeys.SESSION_SMS_CODE)).ToLower())
            {
                return "{\"status\":0, \"msg\":\"您输入的验证码与系统的不一致！\"}";
            }
            context.HttpContext.Session.Remove(CMSKeys.SESSION_SMS_CODE);
            return "success";
        }
        #endregion

        #region 邀请注册处理方法OK=============================
        private string verify_invite_reg(string user_name, string invite_code)
        {
            if (string.IsNullOrEmpty(invite_code))
            {
                return "{\"status\":0, \"msg\":\"邀请码不能为空！\"}";
            }
            User_code codeModel = _user_code.GetModel(invite_code);
            if (codeModel == null)
            {
                return "{\"status\":0, \"msg\":\"邀请码不正确或已过期！\"}";
            }
            if (userConfig.invitecodecount > 0)
            {
                if (codeModel.count >= userConfig.invitecodecount)
                {
                    codeModel.status = 1;
                    return "{\"status\":0, \"msg\":\"该邀请码已经被使用！\"}";
                }
            }
            //检查是否给邀请人增加积分
            if (userConfig.pointinvitenum > 0)
            {
                _user_point_log.Add(codeModel.user_id, codeModel.user_name, userConfig.pointinvitenum, "邀请用户【" + user_name + "】注册获得积分", true);
            }
            //更改邀请码状态
            codeModel.count += 1;
            _user_code.Update(codeModel);
            return "success";
        }
        #endregion

        #region 发送手机短信验证码OK===========================
        private string send_verify_sms_code(ActionExecutingContext context, string mobile)
        {
            //检查手机
            if (string.IsNullOrEmpty(mobile))
            {
                return "{\"status\":0, \"msg\":\"发送失败，请填写手机号码！\"}";
            }
            //检查是否过期
            string cookie = Request.Cookies[CMSKeys.COOKIE_USER_MOBILE];
            if (cookie == mobile)
            {
                return "{\"status\":1, \"time\":\"" + userConfig.regsmsexpired + "\", \"msg\":\"已发送短信，" + userConfig.regsmsexpired + "分钟后再试！\"}";
            }
            var smsModel = _sms_template.GetModel("usercode"); //取得短信内容
            if (smsModel == null)
            {
                return "{\"status\":0, \"msg\":\"发送失败，短信模板不存在，请联系管理员！\"}";
            }
            string strcode = Utils.Number(4); //随机验证码
                                              //替换标签
            string msgContent = smsModel.content;
            msgContent = msgContent.Replace("{webname}", sysConfig.webname);
            msgContent = msgContent.Replace("{weburl}", sysConfig.weburl);
            msgContent = msgContent.Replace("{webtel}", sysConfig.webtel);
            msgContent = msgContent.Replace("{code}", strcode);
            msgContent = msgContent.Replace("{valid}", userConfig.regsmsexpired.ToString());
            //发送短信
            string tipMsg = string.Empty;
            bool result = sendSMS.Send(mobile, smsModel.code, msgContent);
            if (!result)
            {
                return "{\"status\":0, \"msg\":\"发送失败，" + tipMsg + "\"}";
            }
            //写入SESSION，保存验证码
            context.HttpContext.Session.SetString(CMSKeys.SESSION_SMS_CODE,strcode);
            context.HttpContext.Session.SetString(CMSKeys.COOKIE_USER_MOBILE, mobile);//userConfig.regsmsexpired //规定时间内无重复发送
            return "success";
        }
        #endregion

        #region Email验证发送邮件OK============================
        private string send_verify_email(Users userModel)
        {
            //生成随机码
            string strcode = Utils.GetCheckCode(20);
            User_code codeModel;
            //检查是否重复提交
            codeModel = _user_code.GetModel(userModel.user_name, CMSEnums.CodeEnum.RegVerify.ToString(), "d");
            if (codeModel == null)
            {
                codeModel = new User_code();
                codeModel.user_id = userModel.id;
                codeModel.user_name = userModel.user_name;
                codeModel.type = CMSEnums.CodeEnum.RegVerify.ToString();
                codeModel.str_code = strcode;
                codeModel.eff_time = DateTime.Now.AddDays(userConfig.regemailexpired);
                codeModel.add_time = DateTime.Now;
                _user_code.Add(codeModel);
            }
            //获得邮件内容
            var mailModel = _mail_template.GetModel("regverify");
            if (mailModel == null)
            {
                return "{\"status\":0, \"msg\":\"邮件发送失败，邮件模板内容不存在！\"}";
            }
            //替换模板内容
            string titletxt = mailModel.maill_title;
            string bodytxt = mailModel.content;
            titletxt = titletxt.Replace("{webname}", sysConfig.webname);
            titletxt = titletxt.Replace("{username}", userModel.user_name);
            bodytxt = bodytxt.Replace("{webname}", sysConfig.webname);
            bodytxt = bodytxt.Replace("{webtel}", sysConfig.webtel);
            bodytxt = bodytxt.Replace("{weburl}", sysConfig.weburl);
            bodytxt = bodytxt.Replace("{username}", userModel.user_name);
            bodytxt = bodytxt.Replace("{valid}", userConfig.regemailexpired.ToString());
            bodytxt = bodytxt.Replace("{linkurl}", "https://" + Request.Host.Host+"/register?action=checkmail&code=" + codeModel.str_code);
            //发送邮件
            try
            {
                CMSMail.sendMail(sysConfig.emailsmtp, sysConfig.emailssl,
                    sysConfig.emailusername,
                    AESEncryptHelper.Decode(sysConfig.emailpassword, sysConfig.sysencryptstring),
                    sysConfig.emailnickname,
                    sysConfig.emailfrom,
                    userModel.email,
                    titletxt, bodytxt);
            }
            catch
            {
                return "{\"status\":0, \"msg\":\"邮件发送失败，请联系本站管理员！\"}";
            }
            return "success";
        }
        #endregion

        #endregion END通用方法===============================

        #region 添加友情链接================================
        private ContentResult link_add()
        {
            var context = HttpContext;
            StringBuilder strTxt = new StringBuilder();

            Link model = new Link();

            int _site_id = CMSRequest.GetQueryInt("site", context);
            string _code = CMSRequest.GetFormString("txtCode", context);
            string _title = CMSRequest.GetFormString("txtTitle", context);
            string _user_name = CMSRequest.GetFormString("txtUserName", context);
            string _user_tel = CMSRequest.GetFormString("txtUserTel", context);
            string _email = CMSRequest.GetFormString("txtEmail", context);
            string _site_url = CMSRequest.GetFormString("txtSiteUrl", context);
            string _img_url = CMSRequest.GetFormString("txtImgUrl", context);

            //校检验证码
            if (string.IsNullOrEmpty(_code))
            {
                return Content("{\"status\":0, \"msg\":\"对不起，请输入验证码！\"}");
            }
            if (context.Session.GetString(CMSKeys.SESSION_CODE) == null)
            {
                return Content("{\"status\":0, \"msg\":\"对不起，系验证码已过期！\"}");
            }
            if (_code.ToLower() != (context.Session.GetString(CMSKeys.SESSION_CODE)).ToLower())
            {
                return Content("{\"status\":0, \"msg\":\"验证码与系统的不一致！\"}");
            }
            if (string.IsNullOrEmpty(_title))
            {
                return Content("{\"status\": 0, \"msg\": \"对不起，请输入网站标题！\"}");
            }
            if (string.IsNullOrEmpty(_site_url))
            {
                return Content("{\"status\": 0, \"msg\": \"对不起，请输入网站网址！\"}");
            }
            model.title = Utils.DropHTML(_title);
            model.is_lock = 1;
            model.is_red = 0;
            model.user_name = Utils.DropHTML(_user_name);
            model.user_tel = Utils.DropHTML(_user_tel);
            model.email = Utils.DropHTML(_email);
            model.site_url = Utils.DropHTML(_site_url);
            model.img_url = Utils.DropHTML(_img_url);
            model.is_image = 1;
            if (string.IsNullOrEmpty(model.img_url))
            {
                model.is_image = 0;
            }
            if (_link.Add(model) > 0)
            {
                return Content("{\"status\": 1, \"msg\": \"恭喜您，提交成功！\"}");
            }
            return Content("{\"status\": 0, \"msg\": \"对不起，保存过程中发生错误！\"}");
        }
        #endregion

        #region 发布留言================================
        private ContentResult feedback_add( )
        {
            var context = HttpContext;
            StringBuilder strTxt = new StringBuilder();
            Feedback model = new Feedback();

            int _site_id = CMSRequest.GetQueryInt("site", context);
            string _code = CMSRequest.GetFormString("txtCode", context);
            string _title = CMSRequest.GetFormString("txtTitle", context);
            string _content = CMSRequest.GetFormString("txtContent", context);
            string _user_name = CMSRequest.GetFormString("txtUserName", context);
            string _user_tel = CMSRequest.GetFormString("txtUserTel", context);
            string _user_qq = CMSRequest.GetFormString("txtUserQQ", context);
            string _user_email = CMSRequest.GetFormString("txtUserEmail", context);

            //校检验证码
            if (string.IsNullOrEmpty(_code))
            {
                return Content("{\"status\":0, \"msg\":\"对不起，请输入验证码！\"}");
            }
            if (context.Session.GetString(CMSKeys.SESSION_CODE) == null)
            {
                return Content("{\"status\":0, \"msg\":\"对不起，验证码已过期！\"}");
            }
            if (_code.ToLower() != (context.Session.GetString(CMSKeys.SESSION_CODE)).ToLower())
            {
                return Content("{\"status\":0, \"msg\":\"验证码与系统的不一致！\"}");
            }
            if (string.IsNullOrEmpty(_content))
            {
                return Content("{\"status\": 0, \"msg\": \"对不起，请输入留言的内容！\"}");
            }
            model.title = Utils.DropHTML(_title);
            model.content = Utils.ToHtml(_content);
            model.user_name = Utils.DropHTML(_user_name);
            model.user_tel = Utils.DropHTML(_user_tel);
            model.user_qq = Utils.DropHTML(_user_qq);
            model.user_email = Utils.DropHTML(_user_email);
            model.add_time = DateTime.Now;
            model.is_lock = 1; //不需要审核，请改为0
            if (_feeback.Add(model) > 0)
            {
                return Content("{\"status\": 1, \"msg\": \"恭喜您，留言提交成功！\"}");
            }
            return Content("{\"status\": 0, \"msg\": \"对不起，保存过程中发生错误！\"}");
        }
        #endregion

        #region 绑定第三方登录账户OK===========================
        private ContentResult user_oauth_bind()
        {
            var context = HttpContext;
            //检查URL参数
            if (context.Session.GetString("oauth_name") == null)
            {
                return Content("{\"status\": 0, \"msg\": \"错误提示：授权参数不正确！\"}");
            }
            //获取授权信息
            if (HttpContext.Session.GetString("oauth_name") == null || HttpContext.Session.GetString("oauth_access_token") == null || HttpContext.Session.GetString("oauth_openid") == null)
            {
                return Content("{\"status\":\"0\", \"msg\":\"出错啦，Access Token已过期或不存在！\"}");
            }
            string oauth_name = HttpContext.Session.GetString("oauth_name");
            string oauth_access_token = HttpContext.Session.GetString("oauth_access_token");
            string oauth_openid = HttpContext.Session.GetString("oauth_openid");
            var result = weixin(oauth_name, oauth_access_token, oauth_openid);
            //反序列化JSON
            Dictionary<string, object> dic = JsonHelper.DataRowFromJSON(result);
            if (dic["ret"].ToString() != "0")
            {
                return Content("{\"status\": 0, \"msg\": \"错误代码：" + dic["ret"] + "，描述：" + dic["msg"] + "\"}");
            }
            #region 是否关注公众号 默认不检测
            if (userConfig.subscribe == 1)
            {
                string sub_AccessToken = HttpContext.Session.GetString("sub_AccessToken");
                var subs = weixin_helper.get_info_subscribe(sub_AccessToken, oauth_openid);
                string guanzhu = subs["subscribe"].ToString();//是否关注公众号1/0

                if (!string.IsNullOrEmpty(guanzhu))
                {
                    if (guanzhu == "0")
                    {
                        return Content("{\"status\":1, \"url\":\""
                        + "/Home/Weixin\", \"msg\":\"请先关注公众号再绑定！\"}");
                    }
                }
                else
                {
                    return Content("{\"status\":1, \"url\":\""
                        + "/Home/Weixin\", \"msg\":\"请先关注公众号再绑定！\"}");
                }
            }
            #endregion
            //检查用户名密码
            string username = CMSRequest.GetString("txtUserName",HttpContext);
            string password = CMSRequest.GetString("txtPassword",HttpContext);
            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
            {
                return Content("{\"status\": 0, \"msg\": \"温馨提示：请输入用户名或密码！\"}");
            }
            Users model = _users.GetModel(username, password, userConfig.emaillogin, userConfig.mobilelogin, true);
            if (model == null)
            {
                return Content("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
            }
            //开始绑定
            User_oauth oauthModel = new User_oauth();
            oauthModel.oauth_name = dic["oauth_name"].ToString();
            oauthModel.user_id = model.id;
            oauthModel.user_name = model.user_name;
            oauthModel.oauth_access_token = dic["oauth_access_token"].ToString();
            oauthModel.oauth_openid = dic["oauth_openid"].ToString();
            int newId = _user_oauth.Add(oauthModel);
            if (newId < 1)
            {
                return Content("{\"status\":0, \"msg\":\"错误提示：绑定过程中出错，请重新获取！\"}");
            }            
            context.Session.Set(CMSKeys.SESSION_USER_INFO, ByteConvertHelper.Object2Bytes(model));
            //记住登录状态，防止Session提前过期
            context.Response.Cookies.Append(CMSKeys.COOKIE_USER_NAME_REMEMBER, model.user_name);
            context.Response.Cookies.Append(CMSKeys.COOKIE_USER_PWD_REMEMBER, model.password);
            //写入登录日志
            _user_login_log.Add(model.id, model.user_name, "会员登录",CMSRequest.GetClientUserIp(context));
            //返回URL
            return Content("{\"status\":1, \"msg\":\"会员登录成功！\"}");
        }
        private string weixin(string oauth_name, string oauth_access_token, string oauth_openid)
        {
            Dictionary<string, object> dic = weixin_helper.get_info(oauth_access_token, oauth_openid);
            if (dic == null)
            {
                return "{\"ret\":\"1\", \"msg\":\"出错啦，无法获取授权用户信息！\"}";
            }
            StringBuilder str = new StringBuilder();
            str.Append("{");
            str.Append("\"ret\": \"0\", ");
            str.Append("\"msg\": \"获得用户信息成功！\", ");
            str.Append("\"oauth_name\": \"" + oauth_name + "\", ");
            str.Append("\"oauth_access_token\": \"" + oauth_access_token + "\", ");
            str.Append("\"oauth_openid\": \"" + dic["openid"].ToString() + "\", ");
            str.Append("\"nick\": \"" + dic["nickname"].ToString() + "\", ");
            str.Append("\"avatar\": \"" + dic["headimgurl"].ToString() + "\", ");
            if (dic["sex"].ToString() == "1")
            {
                str.Append("\"sex\": \"男\", ");
            }
            else if (dic["sex"].ToString() == "2")
            {
                str.Append("\"sex\": \"女\", ");
            }
            else
            {
                str.Append("\"sex\": \"保密\", ");
            }
            str.Append("\"birthday\": \"\"");
            str.Append("}");

            return str.ToString();
        }
        #endregion

        #region 注册第三方注册账户OK===========================
        private ContentResult user_oauth_register()
        {
            if (1==1)
            {
                return Content("{\"status\": 0, \"msg\": \"错误提示：管理员禁用微信注册！\"}");
            }
            var context = HttpContext;
            //检查URL参数
            if (context.Session.GetString("oauth_name") == null)
            {
                return Content("{\"status\": 0, \"msg\": \"错误提示：授权参数不正确！\"}");
            }
            //获取授权信息
            string oauth_name = HttpContext.Session.GetString("oauth_name");
            string oauth_access_token = HttpContext.Session.GetString("oauth_access_token");
            string oauth_openid = HttpContext.Session.GetString("oauth_openid");
            var result = weixin(oauth_name, oauth_access_token, oauth_openid);

            string password = CMSRequest.GetFormString("txtPassword",context).Trim();
            string email = Utils.ToHtml(CMSRequest.GetFormString("txtEmail", context).Trim());
            string mobile = Utils.ToHtml(CMSRequest.GetFormString("txtMobile", context).Trim());
            string userip = CMSRequest.GetClientUserIp(context);
            //反序列化JSON
            Dictionary<string, object> dic = JsonHelper.DataRowFromJSON(result);
            if (dic["ret"].ToString() != "0")
            {
                return Content("{\"status\": 0, \"msg\": \"错误代码：" + dic["ret"] + "，" + dic["msg"] + "\"}");
            }
            Users model = new Users();
            //如果开启手机登录要验证手机
            if (userConfig.mobilelogin == 1 && !string.IsNullOrEmpty(mobile))
            {
                if (_users.ExistsMobile(mobile))
                {
                    return Content("{\"status\":0, \"msg\":\"对不起，该手机号码已被使用！\"}");
                }
            }
            //如果开启邮箱登录要验证邮箱
            if (userConfig.emaillogin == 1 && !string.IsNullOrEmpty(email))
            {
                if (_users.ExistsEmail(email))
                {
                    return Content("{\"status\":0, \"msg\":\"对不起，该电子邮箱已被使用！\"}");
                }
            }
            //检查默认组别是否存在
            User_groups modelGroup = _user_groups.GetDefault();
            if (modelGroup == null)
            {
                return Content("{\"status\":0, \"msg\":\"用户尚未分组，请联系管理员！\"}");
            }
            //保存注册信息
            model.group_id = modelGroup.id;
            model.user_name = _users.GetRandomName(10); //随机用户名
            model.salt = Utils.GetCheckCode(6); //获得6位的salt加密字符串
            model.password = AESEncryptHelper.Encode(password, model.salt);
            model.email = email;
            model.mobile = mobile;
            if (!string.IsNullOrEmpty(dic["nick"].ToString()))
            {
                model.nick_name = dic["nick"].ToString();
            }
            if (dic["avatar"].ToString().StartsWith("https://")|| dic["avatar"].ToString().StartsWith("http://"))
            {
                model.avatar = dic["avatar"].ToString();
            }
            if (!string.IsNullOrEmpty(dic["sex"].ToString()))
            {
                model.sex = dic["sex"].ToString();
            }
            if (!string.IsNullOrEmpty(dic["birthday"].ToString()))
            {
                model.birthday = Utils.StrToDateTime(dic["birthday"].ToString());
            }
            model.reg_ip = userip;
            model.reg_time = DateTime.Now;
            model.status = 0; //设置为正常状态
            model.id = _users.Add(model); //保存数据
            if (model.id < 1)
            {
                return Content("{\"status\":0, \"msg\":\"注册失败，请联系网站管理员！\"}");
            }
            //赠送积分金额
            if (modelGroup.point > 0)
            {
                _user_point_log.Add(model.id, model.user_name, modelGroup.point, "注册赠送积分", false);
            }
            if (modelGroup.amount > 0)
            {
                _user_amount_log.Add(model.id, model.user_name, modelGroup.amount, "注册赠送金额");
            }
            //判断是否发送欢迎消息
            if (userConfig.regmsgstatus == 1) //站内短消息
            {
                _user_message.Add(1, "", model.user_name, "欢迎您成为本站会员", userConfig.regmsgtxt);
            }
            else if (userConfig.regmsgstatus == 2) //发送邮件
            {
                //取得邮件模板内容
                Mail_template mailModel = _mail_template.GetModel("welcomemsg");
                if (mailModel != null)
                {
                    //替换标签
                    string mailTitle = mailModel.maill_title;
                    mailTitle = mailTitle.Replace("{username}", model.user_name);
                    string mailContent = mailModel.content;
                    mailContent = mailContent.Replace("{webname}", sysConfig.webname);
                    mailContent = mailContent.Replace("{weburl}", sysConfig.weburl);
                    mailContent = mailContent.Replace("{webtel}", sysConfig.webtel);
                    mailContent = mailContent.Replace("{username}", model.user_name);
                    //发送邮件
                    CMSMail.sendMail(sysConfig.emailsmtp, sysConfig.emailssl,
                        sysConfig.emailusername,
                        AESEncryptHelper.Decode(sysConfig.emailpassword, sysConfig.sysencryptstring),
                        sysConfig.emailnickname,
                        sysConfig.emailfrom,
                        model.email,
                        mailTitle, mailContent);
                }
            }
            else if (userConfig.regmsgstatus == 3 && mobile != "") //发送短信
            {
                Sms_template smsModel = _sms_template.GetModel("welcomemsg"); //取得短信内容
                if (smsModel != null)
                {
                    //替换标签
                    string msgContent = smsModel.content;
                    msgContent = msgContent.Replace("{webname}", sysConfig.webname);
                    msgContent = msgContent.Replace("{weburl}", sysConfig.weburl);
                    msgContent = msgContent.Replace("{webtel}", sysConfig.webtel);
                    msgContent = msgContent.Replace("{username}", model.user_name);
                    //发送短信
                    sendSMS.Send(model.mobile,smsModel.code, msgContent);
                }
            }
            //绑定到对应的授权类型
            User_oauth oauthModel = new User_oauth();
            oauthModel.oauth_name = dic["oauth_name"].ToString();
            oauthModel.user_id = model.id;
            oauthModel.user_name = model.user_name;
            oauthModel.oauth_access_token = dic["oauth_access_token"].ToString();
            oauthModel.oauth_openid = dic["oauth_openid"].ToString();
            _user_oauth.Add(oauthModel);

            context.Session.Set(CMSKeys.SESSION_USER_INFO, ByteConvertHelper.Object2Bytes(model));
            //记住登录状态，防止Session提前过期
            context.Response.Cookies.Append(CMSKeys.COOKIE_USER_NAME_REMEMBER, model.user_name);
            context.Response.Cookies.Append(CMSKeys.COOKIE_USER_PWD_REMEMBER, model.password);
            //写入登录日志
            _user_login_log.Add(model.id, model.user_name, "会员登录",CMSRequest.GetClientUserIp(context));
            //返回URL
            return Content("{\"status\":1, \"msg\":\"会员登录成功！\"}");
        }
        #endregion

        #region Finance
        #region 输出购物车总数OK===============================
        private ContentResult view_cart_count()
        {
            return Content("document.write('" + shopcart.GetQuantityCount() + "');");
        }
        #endregion

        #region 验证直推人是否可用OK============================
        private ContentResult direct_validate()
        {
            string username = Request.Form["param"];
            //如果为Null，退出
            if (string.IsNullOrEmpty(username))
            {
                return Content("{ \"info\":\"直推人不可为空\", \"status\":\"n\" }");
            }
            //过滤注册用户名字符
            string[] strArray = userConfig.regkeywords.Split(',');
            foreach (string s in strArray)
            {
                if (s.ToLower() == username.ToLower())
                {
                    return Content("{ \"info\":\"该直推人不可用\", \"status\":\"n\" }");
                }
            }
            //查询数据库
            if (!_users.Exists(username.Trim()))
            {
                return Content("{ \"info\":\"该直推人不存在\", \"status\":\"n\" }");
            }
            var duser = _users.GetModel(username);
            if (duser.is_share == 0)
            {
                return Content("{ \"info\":\"该直推人禁止分享\", \"status\":\"n\" }");
            }
            if (duser.is_lock == 1)
            {
                return Content("{ \"info\":\"该直推人已被锁定\", \"status\":\"n\" }");
            }
            return Content("{ \"info\":\"用户名:" + duser.nick_name + "\", \"status\":\"y\" }");
        }
        #endregion

        #region 验证接点人是否可用OK============================
        private ContentResult indirect_validate()
        {
            string username = Request.Form["param"];
            //如果为Null，退出
            if (string.IsNullOrEmpty(username))
            {
                return Content("{ \"info\":\"接点人不可为空\", \"status\":\"n\" }");
            }
            //过滤注册用户名字符
            string[] strArray = userConfig.regkeywords.Split(',');
            foreach (string s in strArray)
            {
                if (s.ToLower() == username.ToLower())
                {
                    return Content("{ \"info\":\"该接点人不可用\", \"status\":\"n\" }");
                }
            }
            //查询数据库
            if (!_users.Exists(username.Trim()))
            {
                return Content("{ \"info\":\"该接点人不存在\", \"status\":\"n\" }");
            }
            var duser = _users.GetModel(username);
            if (duser.is_share == 0)
            {
                return Content("{ \"info\":\"该接点人禁止分享\", \"status\":\"n\" }");
            }
            if (duser.is_lock == 1)
            {
                return Content("{ \"info\":\"该接点人已被锁定\", \"status\":\"n\" }");
            }
            return Content("{ \"info\":\"用户名:" + duser.nick_name + "\", \"status\":\"y\" }");
        }
        #endregion

        #region 升级用户级别=================================
        private ContentResult upgrade()
        {
            //检查用户是否登录
            var userModel = GetUserInfo();
            if (userModel == null)
            {
                return Content("{\"status\":0, \"msg\":\"对不起，用户尚未登录或已超时！\"}");
            }
            if (userModel.password2 != CMSRequest.GetFormString("txtPassword2",HttpContext))
            {
                return Content("{\"status\":0, \"msg\":\"对不起，二级密码不正确！\"}");
            }
            if (userModel.is_pass == 0)
            {
                return Content("{\"status\":0, \"msg\":\"对不起，请先激活！\"}");
            }
            int levelid = CMSRequest.GetFormInt("txtLevelId", userModel.level_id,HttpContext);
            if (levelid< userModel.level_id)
            {
                return Content("{\"status\":0, \"msg\":\"对不起，升级失败！\"}");
            }
            return Content("{\"status\":1, \"msg\":\"用户升级成功！\"}");
        }
        #endregion 

        #region 商户资金提现=================================
        private ContentResult shoppoint_tixian()
        {
            //检查用户是否登录
            var model = GetUserInfo();
            var shop = _shop.GetFirstByUserId(model.id);
            if (model == null)
            {
                return Content("{\"status\":0, \"msg\":\"对不起，用户尚未登录或已超时！\"}");
            }
            decimal point = CMSRequest.GetFormDecimal("point", 0, HttpContext);
            point = Math.Floor(point / userConfig.tixian_base) * userConfig.tixian_base;
            if (userConfig.tixian_switch == 1)
            {
                return Content("{\"status\":0, \"msg\":\"对不起，提现功能关闭！\"}");
            }
            #region 工作日
            string week = DateTime.Today.DayOfWeek.ToString();
            switch (week)
            {
                case "Monday":
                    week = "星期一";
                    break;
                case "Tuesday":
                    week = "星期二";
                    break;
                case "Wednesday":
                    week = "星期三";
                    break;
                case "Thursday":
                    week = "星期四";
                    break;
                case "Friday":
                    week = "星期五";
                    break;
                case "Saturday":
                    week = "星期六";
                    break;
                case "Sunday":
                    week = "星期日";
                    break;
            }
            #endregion
            if (!userConfig.tixian_week.Contains(week))
            {
                return Content("{\"status\":0, \"msg\":\"对不起，" + week + "不可提现,仅" + userConfig.tixian_week + "可提！\"}");
            }
            if (point < userConfig.tixian_start)
            {
                return Content("{\"status\":0, \"msg\":\"对不起，请输入正确的最少" + userConfig.tixian_start + "提现金额(" + userConfig.tixian_base + "的倍数)！\"}");
            }
            var apply = _shop_apply.GetFirst(shop.id);
            if (apply != null)
            {
                return Content("{\"status\":0, \"msg\":\"对不起，提现申请中！\"}");
            }
            if (apply != null)
            {
                if (Utils.IsInSameWeek(apply.add_time, DateTime.Now))
                {
                    return Content("{\"status\":0, \"msg\":\"对不起，每周只能提一次！\"}");
                }
            }
            //提现
            if (shop.point < point)//现金积分
            {
                return Content("{\"status\":0, \"msg\":\"对不起，金额不足！\"}");
            }
            //生成申请记录
            Shop_Apply ap = new Shop_Apply();
            ap.shop_id = shop.id;
            ap.apply_point = point;
            bool flag = _shop_apply.Add(ap);
            if (!flag)
                return Content("{\"status\":0, \"msg\":\"对不起，提现失败！\"}");
            //保存成功后返回
            return Content("{\"status\":1, \"msg\":\"提现申请成功！\"}");

        }
        #endregion                

        #region 激活报单人员==========================
        private ContentResult baodan_pass()
        {
            //检查用户是否登录
            var userModel = GetUserInfo();
            if (userModel == null)
            {
                return Content("{\"status\":0, \"msg\":\"对不起，用户尚未登录或已超时！\"}");
            }
            //检查订单是否存在
            string name = CMSRequest.GetFormString("point",HttpContext);
            if (string.IsNullOrEmpty(name))
            {
                return Content("{\"status\":0, \"msg\":\"对不起，会员不存在！\"}");
            }
            var song = _users.GetModel(name);
            if ( song == null)
            {
                return Content("{\"status\":0, \"msg\":\"对不起，会员不存在！\"}");
            }
            //检查订单状态
            if (song.is_pass != 0)
            {
                return Content("{\"status\":0, \"msg\":\"对不起，已经激活不能重复激活！\"}");
            }
            if (userModel.cash_point < 100000)
            {
                return Content("{\"status\":0, \"msg\":\"对不起，金额不足！\"}");
            }
            _users.UpdateField(userModel.id, "cash_point-=" + 0);//减
            _users.UpdateField(song.id, "cash_point+=" + 0);//加            
            //把余额转让给会员
            if (1==1)
            {
                return Content("{\"status\":1, \"msg\":\"成功激活！\"}");
            }
            else
            {
                return Content("{\"status\":0, \"msg\":\"对不起，激活失败！\"}");
            }
        }
        #endregion

        #region 用户自身激活审核=============================
        private ContentResult user_pass()
        {
            //检查用户是否登录
            var userModel = GetUserInfo();
            if (userModel == null)
            {
                return Content("{\"status\":0, \"msg\":\"对不起，用户尚未登录或已超时！\"}");
            }
            //审过不用再审
            if (userModel.is_pass == 1)
            {
                return Content("{\"status\":0, \"msg\":\"对不起，已经激活不用激活！\"}");
            }
            decimal money = 100000000;

                return Content("{\"status\":1, \"msg\":\"金额不足无法激活！\"}");
            
        }
        #endregion

        #region 用户资金提现=================================
        private ContentResult user_point_tixian()
        {
            //检查用户是否登录
            var model = GetUserInfo();
            if (model == null)
            {
                return Content("{\"status\":0, \"msg\":\"对不起，用户尚未登录或已超时！\"}");
            }
            decimal point = CMSRequest.GetFormDecimal("point", 0,HttpContext);
            point = Math.Floor(point / userConfig.tixian_base) * userConfig.tixian_base;
            if (userConfig.tixian_switch==0)
            {
                return Content("{\"status\":0, \"msg\":\"对不起，提现功能关闭！\"}");
            }
            #region 工作日
            string week = DateTime.Today.DayOfWeek.ToString();
            switch (week)
            {
                case "Monday":
                    week = "星期一";
                    break;
                case "Tuesday":
                    week = "星期二";
                    break;
                case "Wednesday":
                    week = "星期三";
                    break;
                case "Thursday":
                    week = "星期四";
                    break;
                case "Friday":
                    week = "星期五";
                    break;
                case "Saturday":
                    week = "星期六";
                    break;
                case "Sunday":
                    week = "星期日";
                    break;
            }
            #endregion
            if (!userConfig.tixian_week.Contains(week))
            {
                return Content("{\"status\":0, \"msg\":\"对不起，" + week + "不可提现,仅" + userConfig.tixian_week + "可提！\"}");
            }
            if (point < userConfig.tixian_start)
            {
                return Content("{\"status\":0, \"msg\":\"对不起，请输入正确的最少" + userConfig.tixian_start + "提现金额(" + userConfig.tixian_base + "的倍数)！\"}");
            }
            var apply = _apply.GetFirst(model.id);
            if (apply != null)
            {
                return Content("{\"status\":0, \"msg\":\"对不起，提现申请中！\"}");
            }
            if (apply != null)
            {
                if (Utils.IsInSameWeek(apply.add_time, DateTime.Now))
                {
                    return Content("{\"status\":0, \"msg\":\"对不起，每周只能提一次！\"}");
                }
            }
            //银行信息
            if (string.IsNullOrEmpty(model.bank_name))
            {
                return Content("{\"status\":0, \"msg\":\"对不起，请完善提现账户！\"}");
            }
            //银行信息
            if (string.IsNullOrEmpty(model.bank_number))
            {
                return Content("{\"status\":0, \"msg\":\"对不起，请完善卡号！\"}");
            }
            //提现
            if (model.cash_point < point)//现金积分
            {
                return Content("{\"status\":0, \"msg\":\"对不起，金额不足！\"}");
            }
            //生成申请记录
            Apply ap = new Apply();
            ap.user_id = model.id;
            ap.apply_point = point;
            bool flag = _apply.Add(ap);
            if (!flag)
                return Content("{\"status\":0, \"msg\":\"对不起，提现失败！\"}");
            //保存成功后返回
            return Content("{\"status\":1, \"msg\":\"提现申请成功！\"}");

        }
        #endregion                

        #region 向其它会员转币或者向商户支付===============================
        private ContentResult user_point_transfer()
        {
            //检查用户是否登录
            var model = GetUserInfo();
            if (model == null)
            {
                return Content("{\"status\":0, \"msg\":\"对不起，用户尚未登录或已超时！\"}");
            }
            if(userConfig.transfer==0)
            {
                return Content("{\"status\": 0, \"msg\": \"错误提示：未开启转让功能！\"}");
            }
            decimal point = CMSRequest.GetFormDecimal("point", 0,HttpContext);

            string transfer_id = CMSRequest.GetFormString("transfer_id",HttpContext);
            var touser = _users.GetModel(transfer_id);
            if (touser == null)
            {
                return Content("{\"status\": 0, \"msg\": \"错误提示：转出的会员不存在！\"}");
            }
            if (touser.id == model.id)
            {
                return Content("{\"status\": 0, \"msg\": \"错误提示：不能转向自己！\"}");
            }
            //检查站点目录
            if (point <= 0)
            {
                return Content("{\"status\":0, \"msg\":\"对不起，请输入正确的积分！\"}");
            }
            //转分
            if (model.cash_point < point)//不足
            {
                return Content("{\"status\":0, \"msg\":\"对不起， 金额不足！\"}");
            }
            #region Transfer
            Transfer tf = new Transfer();
            tf.from_user_id = model.id;
            tf.to_user_id = touser.id;
            tf.point = point;
            tf.remark = "奖金转让";
            bool flag=_transfer.Add(tf);
            #endregion
            if (flag)
            {
                //保存成功后返回
                return Content("{\"status\":1, \"msg\":\"转让成功！\"}");
            }
            else
            {
                //保存成功后返回
                return Content("{\"status\":0, \"msg\":\"转让失败！\"}");
            }
        }
        private ContentResult user_pay()
        {
            //检查用户是否登录
            var model = GetUserInfo();
            if (model == null)
            {
                return Content("{\"status\":0, \"msg\":\"对不起，用户尚未登录或已超时！\"}");
            }
            decimal point = CMSRequest.GetFormDecimal("point", 0, HttpContext);
            //商铺id
            int transfer_id = CMSRequest.GetFormInt("transfer_id", HttpContext);
            int leixing = CMSRequest.GetFormInt("leixing", HttpContext);
            var shop = _shop.GetModel(transfer_id);
            if (shop == null)
            {
                return Content("{\"status\": 0, \"msg\": \"错误提示：转出的商铺不存在！\"}");
            }
            var touser = _users.GetModel(shop.user_id);
            if (touser == null)
            {
                return Content("{\"status\": 0, \"msg\": \"错误提示：转出的商铺会员不存在！\"}");
            }
            if (touser.id == model.id)
            {
                return Content("{\"status\": 0, \"msg\": \"错误提示：不能转向自己！\"}");
            }
            if (point <= 0)
            {
                return Content("{\"status\":0, \"msg\":\"对不起，请输入正确的积分！\"}");
            }
            if (leixing != 0 && leixing != 1 && leixing != 2)
            {
                return Content("{\"status\":0, \"msg\":\"对不起， 请选择支付类型！\"}");
            }
            if (leixing == 0 && model.cash_point < point)
            {
                return Content("{\"status\":0, \"msg\":\"对不起， 余额不足！\"}");
            }
            if (leixing == 1 && model.shop_point < point * 0.2m || leixing == 1 && model.shop_point < point * 0.8m)//积分余额不足
            {
                return Content("{\"status\":0, \"msg\":\"对不起， 余额+积分不足！\"}");
            }
            //if (leixing == 2 && model.fenhongPoint < point)
            //{
            //    return Content("{\"status\":0, \"msg\":\"对不起， 分红不足！\"}");
            //}
            bool flag = _shop_bills.Add(model.id, shop.id, point, leixing);
            if (flag)
            {
                //保存成功后返回
                return Content("{\"status\":1, \"msg\":\"支付成功！\", \"url\":\"" + "/home/error?msg=" + model.user_name + "向【" + shop.shopname + "】商家成功支付：" + point + "元" + "\"}");
            }
            else
            {
                //保存成功后返回
                return Content("{\"status\":0, \"msg\":\"支付失败！\", \"url\":\"" + "/home/error?msg=支付失败" + "\"}");
            }
        }
        #endregion

        #region 把重消转换成购物金额===============================
        private ContentResult user_point_conversion()
        {
            //检查用户是否登录
            var model = GetUserInfo();
            if (model == null)
            {
                return Content("{\"status\":0, \"msg\":\"对不起，用户尚未登录或已超时！\"}");
            }
            decimal point = CMSRequest.GetFormDecimal("point", 0, HttpContext);

            int payment_id = CMSRequest.GetFormInt("payment_id", 0, HttpContext);
            if(userConfig.cash2amount==0&&payment_id==2)
            {
                return Content("{\"status\":0, \"msg\":\"对不起，未开始奖金转购物！\"}");
            }
            if (userConfig.shop2amount == 0 && payment_id == 1)
            {
                return Content("{\"status\":0, \"msg\":\"对不起，未开始重消转购物！\"}");
            }
            //检查站点目录
            if (point <= 0)
            {
                return Content("{\"status\":0, \"msg\":\"对不起，请输入正确的积分！\"}");
            }
            //转分
            if (model.cash_point < point && payment_id == 2 || model.shop_point < point && payment_id == 1 || point < 0)//不足
            {
                return Content("{\"status\":0, \"msg\":\"对不起， 转换金额不足！\"}");
            }
            if (payment_id != 1 && payment_id != 2)
            {
                return Content("{\"status\":0, \"msg\":\"对不起， 转换类型错误！\"}");
            }
            string strvalue = "";
            string remark = "";
            if (payment_id == 2)
            {
                strvalue = "cash_point-=" + point + ",amount+=" + point;
                remark = "奖金转换";
            }
            else
            {
                strvalue = "shop_point-=" + point + ",amount+=" + point;
                remark = "重消转换";
            }
            if (_users.UpdateField(model.id, strvalue) > 0)
            {
                Bills bill = new Bills();
                bill.user_id = model.id;
                bill.point = point;
                bill.status = 8;
                bill.remark = remark;
                _bills.Add(bill);
                //保存成功后返回
                return Content("{\"status\":1, \"msg\":\"转换成功！\"}");
            }
            else
            {
                //保存成功后返回
                return Content("{\"status\":0, \"msg\":\"转换失败！\"}");
            }
        }
        #endregion

        #region 验证转让名是否可用===========================
        private ContentResult validate_touser()
        {
            string username = CMSRequest.GetString("param",HttpContext);
            //如果为Null，退出
            if (string.IsNullOrEmpty(username))
            {
                return Content("{ \"info\":\"用户名不可为空\", \"status\":\"n\" }");
            }
            //过滤注册用户名字符
            string[] strArray = "admin,root,vipms,manager".Split(',');
            foreach (string s in strArray)
            {
                if (s.ToLower() == username.ToLower())
                {
                    return Content("{ \"info\":\"该用户名不可用\", \"status\":\"n\" }");
                }
            }
            //查询数据库
            if (_users.Exists(username.Trim()))
            {
                return Content("{ \"info\":\"确认用户[" + _users.GetModel(username.Trim()).nick_name + "]\", \"status\":\"y\" }");
            }
            return Content("{ \"info\":\"该用户名不可用\", \"status\":\"n\" }");
        }
        #endregion
        #endregion
    }
}